Re: [PHP] Re: Epiphany - a salute to APC

2009-07-05 Thread Michael A. Peters

Brandon Johnson wrote:
you think this is similar to http://www.danga.com/memcached/ or you think 
this method would be faster ? Which do you say would be the greatest 
benfit ?




In my case I think apc is better because I'm single server xen host and 
(after reading the other posts in thread) most of my data rarely 
changes. New data is added but existing data doesn't change often.


-=- (from other discussion)
Interesting that facebook uses both. The fedora maintainer for the apc 
rpm listed it as conflicting with memcache. If you can use both, that's 
a fedora packaging but that should be fixed.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Epiphany - a salute to APC

2009-07-05 Thread Eddie Drapkin
> -=- (from other discussion)
> Interesting that facebook uses both. The fedora maintainer for the apc rpm
> listed it as conflicting with memcache. If you can use both, that's a fedora
> packaging but that should be fixed.

I've never seen, nor heard of, a full scale caching implementation
that doesn't use both.  Digg uses both, too.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Editing PEAR packages

2009-07-05 Thread Waynn Lue
I wanted to makes some local edits to a PEAR package that I downloaded in
order to build some custom functionality into it.  What's the best way to
manage this process to ensure that I don't accidentally blow away any
changes if I update the package?  Should I just copy the entire package to
my own source repository, then use that directly instead of the PEAR
package?  And if I do it that way, is there an easy path to upgrade it?

Waynn


[PHP] Re: Editing PEAR packages

2009-07-05 Thread Shawn McKenzie
Waynn Lue wrote:
> I wanted to makes some local edits to a PEAR package that I downloaded in
> order to build some custom functionality into it.  What's the best way to
> manage this process to ensure that I don't accidentally blow away any
> changes if I update the package?  Should I just copy the entire package to
> my own source repository, then use that directly instead of the PEAR
> package?  And if I do it that way, is there an easy path to upgrade it?
> 
> Waynn
> 

You might want to see if you can just extend the classes to get the
functionality you want.  You can override vars and methods from the base
class in your own class.

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Editing PEAR packages

2009-07-05 Thread Greg Beaver
Waynn Lue wrote:
> I wanted to makes some local edits to a PEAR package that I downloaded in
> order to build some custom functionality into it.  What's the best way to
> manage this process to ensure that I don't accidentally blow away any
> changes if I update the package?  Should I just copy the entire package to
> my own source repository, then use that directly instead of the PEAR
> package?  And if I do it that way, is there an easy path to upgrade it?

Best would be to follow Shawn's suggestion.  If you do need to make
changes, you should contribute them back to the package, PEAR is an open
public repository, it may be incorporated and help others in your
situation as well (this is the point of PEAR and of open source).

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] 64 bit binary ?

2009-07-05 Thread loki

Hello

Is it plane to release 64 bit binary for php on windows ?

--
Stéphane

Http://www.arkadia.com/fra/
Http://www.arkadia.com/usa/
Http://www.arkadia.com/rus/ 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Editing PEAR packages

2009-07-05 Thread Waynn Lue
Yeah, that's why I was hoping to maintain a separate install, since it
would be easier to diff the patches.

Shawn: Thanks for the suggestion to extend, I only wanted to make
small changes to an existing function though, so it's harder to do it
that way. My other thought was to refactor the underlying code base to
make it easier.

Waynn

On 7/5/09, Greg Beaver  wrote:
> Waynn Lue wrote:
>> I wanted to makes some local edits to a PEAR package that I downloaded in
>> order to build some custom functionality into it.  What's the best way to
>> manage this process to ensure that I don't accidentally blow away any
>> changes if I update the package?  Should I just copy the entire package to
>> my own source repository, then use that directly instead of the PEAR
>> package?  And if I do it that way, is there an easy path to upgrade it?
>
> Best would be to follow Shawn's suggestion.  If you do need to make
> changes, you should contribute them back to the package, PEAR is an open
> public repository, it may be incorporated and help others in your
> situation as well (this is the point of PEAR and of open source).
>
> Greg
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Editing PEAR packages

2009-07-05 Thread Greg Beaver
Waynn Lue wrote:
> Yeah, that's why I was hoping to maintain a separate install, since it
> would be easier to diff the patches.
>
> Shawn: Thanks for the suggestion to extend, I only wanted to make
> small changes to an existing function though, so it's harder to do it
> that way. My other thought was to refactor the underlying code base to
> make it easier.

Hi Wayne,

If you're only making changes to one function, then you should extend
the class, and override the function.  If the changes are extensive,
then check out the CVS repository, apply your changes, and use the "cvs
diff -u" command to create a patch to send back to the maintainer of the
package.

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] best way to properly build an include path *regardless* from where I am calling the include?

2009-07-05 Thread Govinda

I am confusing myself reading the docs just now.

i.e.:
include_path
basename()
and dirname()

 I had thought from many months ago that

would include
somefile.php
living in
somedir
regardless from where in the site structure I am calling it.

Now it does not seem to be doing that.

What is the safest (portable) way to properly build an include path  
*regardless* from where in my site I am calling the include?
If I understand right I can put includes in a dir/ specified by the  
include_path setting, but I also want to know how to do this from just  
within the root of my virtual server.


-Govinda 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 64 bit binary ?

2009-07-05 Thread Daniel Brown
On Sun, Jul 5, 2009 at 15:43, loki wrote:
> Hello
>
> Is it plane to release 64 bit binary for php on windows ?

Pierre?

-- 

daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: best way to properly build an include path *regardless* from where I am calling the include?

2009-07-05 Thread Govinda

On Jul 5, 2009, at 2:33 PM, Govinda wrote:


I am confusing myself reading the docs just now.

i.e.:
include_path
basename()
and dirname()

I had thought from many months ago that

would include
somefile.php
living in
somedir
regardless from where in the site structure I am calling it.

Now it does not seem to be doing that.

What is the safest (portable) way to properly build an include path  
*regardless* from where in my site I am calling the include?
If I understand right I can put includes in a dir/ specified by the  
include_path setting, but I also want to know how to do this from  
just within the root of my virtual server.


-Govinda


in my include statement, I am now successfully using:
/home/metheuser/public_html/
and am not anticipating moving this site..  but still I am thinking  
there must be a way to make the code bullet proof to dir/ name changes  
*after* the virtual server root.

Or do people just stop here?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: best way to properly build an include path *regardless* from where I am calling the include?

2009-07-05 Thread Govinda

On Jul 5, 2009, at 2:33 PM, Govinda wrote:


I am confusing myself reading the docs just now.

i.e.:
include_path
basename()
and dirname()

I had thought from many months ago that

would include
somefile.php
living in
somedir
regardless from where in the site structure I am calling it.

Now it does not seem to be doing that.

What is the safest (portable) way to properly build an include path  
*regardless* from where in my site I am calling the include?
If I understand right I can put includes in a dir/ specified by the  
include_path setting, but I also want to know how to do this from  
just within the root of my virtual server.


-Govinda


in my include statement, I am now successfully using:
/home/metheuser/public_html/
and am not anticipating moving this site..  but still I am thinking  
there must be a way to make the code bullet proof to dir/ name changes  
*after* the virtual server root.

Or do people just stop here?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: best way to properly build an include path *regardless* from where I am calling the include?

2009-07-05 Thread Michael A. Peters

Govinda wrote:



in my include statement, I am now successfully using:
/home/metheuser/public_html/
and am not anticipating moving this site..  but still I am thinking 
there must be a way to make the code bullet proof to dir/ name changes 
*after* the virtual server root.

Or do people just stop here?



I always define the include path explicitly, and it never includes 
anything inside the web root, but that's just me.


I use

$includeArray[]="/usr/share/pear";
$includeArray[]="/some/other/path";
$includeArray[]="/yet/another/path";

$incPath = impode(':',$includeArray);
ini_set("include_path",$incPath);

Since all my includes are external to the website where they don't ever 
need to moved no matter how I decide to change things, their paths never 
move. Served files inside the web root however can move around freely 
and always find their includes.


I admit, keeping all excludes outside the web root can be a bit tedious, 
but it helps keeps things well organized.


There's more than one way to do it though.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] exasperated again

2009-07-05 Thread Jim Lucas

Stuart wrote:

2009/7/4 PJ :

Stuart wrote:

2009/7/4 PJ :


Ashley Sheridan wrote:


On Sat, 2009-07-04 at 10:47 -0400, PJ wrote:



Jim Lucas wrote:



PJ wrote:



Could somebody please explain to me what is wrong with this code?
In my script it works, returns the correct id, but when I try it in a
test pages, nothing in the world gets it to work. This is rather
frustrating, again:
THIS WORKS IN ANOTHER PAGE; IN THE TEST PAGE ID DOES NOT.
$sql = "SELECT id FROM publishers
WHERE publisher = 'whoever'";
  $result = mysql_query($sql,$db);
$row = mysql_fetch_assoc($result);   if
(mysql_num_rows($result) !== 0) {
  $pub = $row['id'];
Syntax is ok, echo "hello"; works.


This works in the test page:
$aid = array();
$ord = array();
$sql = "SELECT authID, ordinal
FROM book_author WHERE bookid = 624 ORDER BY ordinal ASC";
$result = mysql_query($sql, $db); //$row =
mysql_fetch_assoc($result);
while ( $row = mysql_fetch_assoc($result) ) {
$aid[]=$row['authID'];
$ord[]=$row['ordinal'];
}
var_dump($aid);
echo "";
var_dump($ord);
echo $aid[0], " - ";
echo $ord[0];

This does not:
$fi="joe"; $la="joe";
$sql = "SELECT id FROM author
WHERE first_name = '$fi' && last_name = '$la'";
$result = msql_query($sql, $db);
$row = mysql_fetch_assoc($result);
$count=mysql_num_rows($result);
echo $count;
  if (mysql_num_rows($result) > 0) {
  $a_id=$row['id'];
  }
  echo $a_id, "";
The test page prints out echo "some text"; but no results when the
results are there
Tell me I have missed something simple here, or is this normal for php ?
I have checked the queries on Mysql command line and they are fine.
I have verified the syntax and Netbeans tells me it is fine.
Same results Firefox3 (2 machines) & IE 8.
What is not fine?




I was preaching this to you months ago.  You should have error
reporting turned on in a development area.

by that I mean php should be set to display_errors = on and
error_reporting = E_ALL

Give this a try in a development area and "you will see the errors of
your ways..."




The error reporting is always on as you suggested and I use it all the time.
But error reporting cannot report a non-existing error - a human stupid
error that I finally caught - msql instead of mysql... oh. well... :-(

--
Hervé Kempf: "Pour sauver la planète, sortez du capitalisme."
-
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php





Actually, if you had error reporting on, it should have at least picked
that up as a function that was not defined. You do mention you get a lot
of white pages instead of errors, which suggests that either you do not
have errors turned on, or you are turning them on from within PHP,


What do you mean "from within PHP" ?
Isn't this enough in the script?
error_reporting(E_ALL);
ini_set('display_errors', 1);


As Ash points out that will not display errors in the code syntax
since they prevent any of your script from being executed. You're
better off setting these values in php.ini.

-Stuart



But not on a productions server, right? (Since this should have been
corrected before "going live")


Indeed. If you're using the same server for both then use ini_set to
turn display_errors off on the production site.

-Stuart



Or, if it is running apache, you can set these values from within the httpd.conf file for your respective 
...




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: best way to properly build an include path *regardless* from where I am calling the include?

2009-07-05 Thread Shawn McKenzie
Govinda wrote:
> I am confusing myself reading the docs just now.
> 
> i.e.:
> include_path
> basename()
> and dirname()
> 
>  I had thought from many months ago that
> 
> would include
> somefile.php
> living in
> somedir
> regardless from where in the site structure I am calling it.
> 
> Now it does not seem to be doing that.
> 
> What is the safest (portable) way to properly build an include path
> *regardless* from where in my site I am calling the include?
> If I understand right I can put includes in a dir/ specified by the
> include_path setting, but I also want to know how to do this from just
> within the root of my virtual server.
> 
> -Govinda

AFAIK, include '/somedir/somefile.php'; looks for that specific file in
that specific path because you gave an absolute path.

If you do include 'somedir/somefile.php'; then it looks in all paths in
the include path and appends somedir/somefile.php.  So if your include
path contained /usr/share/php/PEAR for example and somefile.php was at
/usr/share/php/PEAR/somedir/ then it would find it.

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Editing PEAR packages

2009-07-05 Thread Shawn McKenzie
Waynn Lue wrote:
> Yeah, that's why I was hoping to maintain a separate install, since it
> would be easier to diff the patches.
> 
> Shawn: Thanks for the suggestion to extend, I only wanted to make
> small changes to an existing function though, so it's harder to do it
> that way. My other thought was to refactor the underlying code base to
> make it easier.
> 
> Waynn
> 
> On 7/5/09, Greg Beaver  wrote:
>> Waynn Lue wrote:
>>> I wanted to makes some local edits to a PEAR package that I downloaded in
>>> order to build some custom functionality into it.  What's the best way to
>>> manage this process to ensure that I don't accidentally blow away any
>>> changes if I update the package?  Should I just copy the entire package to
>>> my own source repository, then use that directly instead of the PEAR
>>> package?  And if I do it that way, is there an easy path to upgrade it?
>> Best would be to follow Shawn's suggestion.  If you do need to make
>> changes, you should contribute them back to the package, PEAR is an open
>> public repository, it may be incorporated and help others in your
>> situation as well (this is the point of PEAR and of open source).
>>
>> Greg
>>

Well, it depends upon the nature of your changes.

You can copy the parent class's code and modify it in your class, or you
can call parent::somefunc(); in your class and then run your custom
code.  It just depends upon what you are changing and how.

I for one would never have anything in production (or was considered
completed) where I had to diff files or look through code before I
updated a package or framework.  Actually, for me anyway, I wouldn't
update/upgrade any shared library/component on a site/app unless I was
still developing the code and it provided some extra functionality that
I needed, or it patched a security vulnerability or maybe fixed a bad
bug that I was struggling with.

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: best way to properly build an include path *regardless* from where I am calling the include?

2009-07-05 Thread Govinda

On Jul 5, 2009, at 4:17 PM, Michael A. Peters wrote:


I use

$includeArray[]="/usr/share/pear";
$includeArray[]="/some/other/path";
$includeArray[]="/yet/another/path";

$incPath = impode(':',$includeArray);




ini_set("include_path",$incPath);


is that ^  something one can generally set on a shared hosting  
environment?


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: best way to properly build an include path *regardless* from where I am calling the include?

2009-07-05 Thread Govinda


On Jul 5, 2009, at 6:15 PM, Shawn McKenzie wrote:


AFAIK, include '/somedir/somefile.php'; looks for that specific file  
in

that specific path because you gave an absolute path.


Well, that is what I wanted.
So I tried this:
include '/MY_inc_php/GovBC_php_functions.inc';
but that fails.
So I try this:
include '/home/metheuser/public_html/MY_inc_php/ 
GovBC_php_functions.inc';

and it works.

But if I ever have to move to a server where the "home" part of that  
path is not "home", or the "public_html" part of that path is not  
"public_html" (I dunno..  I do not run servers), then my includes break.




If you do include 'somedir/somefile.php'; then it looks in all paths  
in

the include path


Here ^^^  when you say "it looks in all paths in the include path",  
what are you talking about?
It seem like you do not mean the path in my include statement itself,  
but in some string (path) that is built and stored somewhere else.  (?)

Where do I build/store that?


and appends somedir/somefile.php.  So if your include
path contained /usr/share/php/PEAR for example and somefile.php was at
/usr/share/php/PEAR/somedir/ then it would find it.





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] preg_replace with UTF-8

2009-07-05 Thread SleePy
I seem to be having a minor issue with preg_replace not working as  
expected when using UTF-8 strings. So far I have found out that \w  
doesn't seem to be detecting UTF-8 strings.


This is my test php file:
';

$data = preg_replace('~([\w\.]{6})~u', '$1 < >', $data);
echo 'Data After: ', $data;

// UTF-8 Test
$data = 'ффф';
echo 'Data before: ', $data, '';

$data = preg_replace('~([\w\.]{6})~u', '$1 < >', $data);
echo 'Data After: ', $data;

?>


I would expect it to be:
Data before: ooo
Data After: oo < >oo < >oo < >o
---
Data before: ффф
Data After: фф <>фф <>фф<> ф

But what I get is:
Data before: ooo
Data After: oo < >oo < >oo < >o
---
Data before: ффф
Data After: ффф

Did I go about this the wrong way or is this a php bug itself?
I tested this in php 5.3, 5.2.9 and 6.0 (snapshot from a couple weeks  
ago) and received the same results.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Add BCC parameter to mail()

2009-07-05 Thread c...@hosting4days.com

Hi folks - Newbie question...

Q: Is there a way to add BCC and/or CC parameters to this simple email  
function?


If there is a better way to do this - please let me know

Thanks in advance


$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional  
headerfields


$fullto = $recipientname . " <" . $recipient . ">";

ini_set('sendmail_from', 't...@test.com');

mail($fullto, $subject, $mail_body, $header); //mail command :)
?>


Thanks,
c...@hosting4days.com





Re: [PHP] Re: best way to properly build an include path *regardless* from where I am calling the include?

2009-07-05 Thread Shawn McKenzie
Govinda wrote:
> 
> On Jul 5, 2009, at 6:15 PM, Shawn McKenzie wrote:
>>
>> AFAIK, include '/somedir/somefile.php'; looks for that specific file in
>> that specific path because you gave an absolute path.
> 
> Well, that is what I wanted.
> So I tried this:
> include '/MY_inc_php/GovBC_php_functions.inc';
> but that fails.
> So I try this:
> include '/home/metheuser/public_html/MY_inc_php/GovBC_php_functions.inc';
> and it works.

So, depending upon you include path, yes.  The preceding slash states
that its an absolute path.  Starts at the root / nad the a path after that.

> 
> But if I ever have to move to a server where the "home" part of that
> path is not "home", or the "public_html" part of that path is not
> "public_html" (I dunno..  I do not run servers), then my includes break.
> 
>>
>> If you do include 'somedir/somefile.php'; then it looks in all paths in
>> the include path
> 
> Here ^^^  when you say "it looks in all paths in the include path", what
> are you talking about?
> It seem like you do not mean the path in my include statement itself,
> but in some string (path) that is built and stored somewhere else.  (?)
> Where do I build/store that?
> 
>> and appends somedir/somefile.php.  So if your include
>> path contained /usr/share/php/PEAR for example and somefile.php was at
>> /usr/share/php/PEAR/somedir/ then it would find it.
> 
> 
> 
In include_path in php.ini or you can set it in your script.  It's the
path that PHP looks in when you include a file.

Sorry, I thought you knew this and were wanting to know whey one thing
worked and one didn't.

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Lookup domain in directories VS database

2009-07-05 Thread Martin Zvarík

Imagine you are hosting 10.000 subdomains.



SOLUTION #1:

you create directories like:

a/
b/
...
s/
s/some-subdomain.freehosting.com/ (this includes CONF.php, where you 
store some basic infos)



Everytime visitor hits the page you do:

@include('t/test-subdomain.freehosting.com/conf.php')

if (!isset($CONF)) die('such a subdomain does not exist');



SOLUTION #2:

Everytime visitor hits the page you connect & search in a MySQL table 
having 10.000 rows with each domain name and a text field (export_var()) 
that has some parameters you need.



---


What's better?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Simple login form with cookies

2009-07-05 Thread Jason Carson
Hello everyone,

I am trying to create a PHP login script using cookies but am having some
troubles. Here is my setup

index.php -> authenticate.php -> admin.php

I want a login form on index.php that allows me to login with my username
and password and then passes $_POST['username'] and $_POST['password'] to
authenticate.php

Then authenticate.php authenticates against a database of allowed users
(Which I already have setup and it works fine), if a valid user has
entered the correct information then admin.php is loaded...

header("location:admin.php");

...the admin.php code would look something like the following..

Code: [Select]


So basically I think I need to create a cookie from index.php OR
authenticate.php and then pass the information to admin.php.
I set the cookie like this...

setcookie("Admin", $username);

Which file(index.php OR authenticate.php) do I create the cookie and how
do I access the information in the cookie on admin.php?


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Add BCC parameter to mail()

2009-07-05 Thread Ashley Sheridan
On Sun, 2009-07-05 at 18:55 -0700, c...@hosting4days.com wrote:
> Hi folks - Newbie question...
> 
> Q: Is there a way to add BCC and/or CC parameters to this simple email  
> function?
> 
> If there is a better way to do this - please let me know
> 
> Thanks in advance
> 
> 
>  $Name = "test"; //senders name
> $email = "t...@test.com"; //senders e-mail adress
> $recipientname = "test";
> $recipient = "j...@test.com"; //recipient
> $mail_body = "test";
> $subject = "test";
> $header = "From: ". $Name . " <" . $email . ">\r\n"; //optional  
> headerfields
> 
> $fullto = $recipientname . " <" . $recipient . ">";
> 
> ini_set('sendmail_from', 't...@test.com');
> 
> mail($fullto, $subject, $mail_body, $header); //mail command :)
> ?>
> 
> 
> Thanks,
> c...@hosting4days.com
> 
> 
> 
rtfm http://uk3.php.net/manual/en/function.mail.php


Thanks
Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Simple login form with cookies

2009-07-05 Thread Paul M Foster
On Mon, Jul 06, 2009 at 12:03:34AM -0400, Jason Carson wrote:

> Hello everyone,
> 
> I am trying to create a PHP login script using cookies but am having some
> troubles. Here is my setup
> 
> index.php -> authenticate.php -> admin.php
> 
> I want a login form on index.php that allows me to login with my username
> and password and then passes $_POST['username'] and $_POST['password'] to
> authenticate.php
> 
> Then authenticate.php authenticates against a database of allowed users
> (Which I already have setup and it works fine), if a valid user has
> entered the correct information then admin.php is loaded...
> 
> header("location:admin.php");
> 
> ...the admin.php code would look something like the following..
> 
> Code: [Select]
>  if (isset($_COOKIE['username'])) {
> echo "success!";
> } else {
> echo "Failure";
> }
> ?>
> 
> So basically I think I need to create a cookie from index.php OR
> authenticate.php and then pass the information to admin.php.
> I set the cookie like this...
> 
> setcookie("Admin", $username);
> 
> Which file(index.php OR authenticate.php) do I create the cookie and how
> do I access the information in the cookie on admin.php?

Just think about it. I assume you're not going to allow someone to run
admin.php unless they're authenticated. And you plan to determine
whether they're authenticated by checking a cookie. So you can only set
that cookie *after* you've authenticated them. Which means you'll need
to set the cookie after you've processed the results from
authenticate.php. My practice is generally to make forms re-entrant.
That is, the data returned from authenticate.php would be processed by
authenticate.php. You'd need to put a branch in authenticate.php to
determine if this is a fresh invocation of the file, or if the user is
returning data to you. The second time through, you check the returned
values against your database and set your cookie.

Checking the value in the cookie is as you detail it above:
$_COOKIE['blahblah'].

Paul

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Simple login form with cookies

2009-07-05 Thread Jason Carson
> Hello everyone,
>
> I am trying to create a PHP login script using cookies but am having some
> troubles. Here is my setup
>
> index.php -> authenticate.php -> admin.php
>
> I want a login form on index.php that allows me to login with my username
> and password and then passes $_POST['username'] and $_POST['password'] to
> authenticate.php
>
> Then authenticate.php authenticates against a database of allowed users
> (Which I already have setup and it works fine), if a valid user has
> entered the correct information then admin.php is loaded...
>
> header("location:admin.php");
>
> ...the admin.php code would look something like the following..
>
> Code: [Select]
>  if (isset($_COOKIE['username'])) {
> echo "success!";
> } else {
> echo "Failure";
> }
> ?>
>
> So basically I think I need to create a cookie from index.php OR
> authenticate.php and then pass the information to admin.php.
> I set the cookie like this...
>
> setcookie("Admin", $username);
>
> Which file(index.php OR authenticate.php) do I create the cookie and how
> do I access the information in the cookie on admin.php?
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
I finally got it working. I needed to setcookie() in login.php. Also, the
names of the cookies(Using setcookie()) where wrong (The names where
"Admin" when they should have been "adminuser" and "adminpass") Once I
fixed that then the following worked in admin.php...



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Simple login form with cookies

2009-07-05 Thread Jason Carson
>> Hello everyone,
>>
>> I am trying to create a PHP login script using cookies but am having
>> some
>> troubles. Here is my setup
>>
>> index.php -> authenticate.php -> admin.php
>>
>> I want a login form on index.php that allows me to login with my
>> username
>> and password and then passes $_POST['username'] and $_POST['password']
>> to
>> authenticate.php
>>
>> Then authenticate.php authenticates against a database of allowed users
>> (Which I already have setup and it works fine), if a valid user has
>> entered the correct information then admin.php is loaded...
>>
>> header("location:admin.php");
>>
>> ...the admin.php code would look something like the following..
>>
>> Code: [Select]
>> > if (isset($_COOKIE['username'])) {
>> echo "success!";
>> } else {
>> echo "Failure";
>> }
>> ?>
>>
>> So basically I think I need to create a cookie from index.php OR
>> authenticate.php and then pass the information to admin.php.
>> I set the cookie like this...
>>
>> setcookie("Admin", $username);
>>
>> Which file(index.php OR authenticate.php) do I create the cookie and how
>> do I access the information in the cookie on admin.php?
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
> I finally got it working. I needed to setcookie() in login.php. Also, the
oops, I typed login.php when I meant authenticate.php
> names of the cookies(Using setcookie()) where wrong (The names where
> "Admin" when they should have been "adminuser" and "adminpass") Once I
> fixed that then the following worked in admin.php...
>  if (isset($_COOKIE['adminuser']) && isset($_COOKIE['adminpass'])) {
> echo "Success";
> } else {
> echo "Failed";
> }
> ?>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Simple login form with cookies

2009-07-05 Thread Eddie Drapkin
On Mon, Jul 6, 2009 at 1:45 AM, Jason Carson wrote:
>> Hello everyone,
>>
>> I am trying to create a PHP login script using cookies but am having some
>> troubles. Here is my setup
>>
>>     index.php -> authenticate.php -> admin.php
>>
>> I want a login form on index.php that allows me to login with my username
>> and password and then passes $_POST['username'] and $_POST['password'] to
>> authenticate.php
>>
>> Then authenticate.php authenticates against a database of allowed users
>> (Which I already have setup and it works fine), if a valid user has
>> entered the correct information then admin.php is loaded...
>>
>> header("location:admin.php");
>>
>> ...the admin.php code would look something like the following..
>>
>> Code: [Select]
>> > if (isset($_COOKIE['username'])) {
>> echo "success!";
>> } else {
>> echo "Failure";
>> }
>> ?>
>>
>> So basically I think I need to create a cookie from index.php OR
>> authenticate.php and then pass the information to admin.php.
>> I set the cookie like this...
>>
>> setcookie("Admin", $username);
>>
>> Which file(index.php OR authenticate.php) do I create the cookie and how
>> do I access the information in the cookie on admin.php?
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
> I finally got it working. I needed to setcookie() in login.php. Also, the
> names of the cookies(Using setcookie()) where wrong (The names where
> "Admin" when they should have been "adminuser" and "adminpass") Once I
> fixed that then the following worked in admin.php...
>  if (isset($_COOKIE['adminuser']) && isset($_COOKIE['adminpass'])) {
> echo "Success";
> } else {
> echo "Failed";
> }
> ?>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

You're not storing anything usable in the adminpass cookie, are you?
It sort of sounds like you're storing a password, or even a passhash,
in the cookie and you might want to rethink what that cookie contains
to prevent session hijacking.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Simple login form with cookies

2009-07-05 Thread Jason Carson
> On Mon, Jul 6, 2009 at 1:45 AM, Jason Carson wrote:
>>> Hello everyone,
>>>
>>> I am trying to create a PHP login script using cookies but am having
>>> some
>>> troubles. Here is my setup
>>>
>>>     index.php -> authenticate.php -> admin.php
>>>
>>> I want a login form on index.php that allows me to login with my
>>> username
>>> and password and then passes $_POST['username'] and $_POST['password']
>>> to
>>> authenticate.php
>>>
>>> Then authenticate.php authenticates against a database of allowed users
>>> (Which I already have setup and it works fine), if a valid user has
>>> entered the correct information then admin.php is loaded...
>>>
>>> header("location:admin.php");
>>>
>>> ...the admin.php code would look something like the following..
>>>
>>> Code: [Select]
>>> >> if (isset($_COOKIE['username'])) {
>>> echo "success!";
>>> } else {
>>> echo "Failure";
>>> }
>>> ?>
>>>
>>> So basically I think I need to create a cookie from index.php OR
>>> authenticate.php and then pass the information to admin.php.
>>> I set the cookie like this...
>>>
>>> setcookie("Admin", $username);
>>>
>>> Which file(index.php OR authenticate.php) do I create the cookie and
>>> how
>>> do I access the information in the cookie on admin.php?
>>>
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>>
>> I finally got it working. I needed to setcookie() in login.php. Also,
>> the
>> names of the cookies(Using setcookie()) where wrong (The names where
>> "Admin" when they should have been "adminuser" and "adminpass") Once I
>> fixed that then the following worked in admin.php...
>> > if (isset($_COOKIE['adminuser']) && isset($_COOKIE['adminpass'])) {
>> echo "Success";
>> } else {
>> echo "Failed";
>> }
>> ?>
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
> You're not storing anything usable in the adminpass cookie, are you?
> It sort of sounds like you're storing a password, or even a passhash,
> in the cookie and you might want to rethink what that cookie contains
> to prevent session hijacking.
>
Yeah, I am storing an unencrypted password in the cookie. Should I encrypt
it, if so how, if not what should I do?

I am new to programming and PHP web development so I am not aware of all
the security problems that can occur.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Simple login form with cookies

2009-07-05 Thread Eddie Drapkin
On Mon, Jul 6, 2009 at 2:01 AM, Jason Carson wrote:
>> On Mon, Jul 6, 2009 at 1:45 AM, Jason Carson wrote:
 Hello everyone,

 I am trying to create a PHP login script using cookies but am having
 some
 troubles. Here is my setup

     index.php -> authenticate.php -> admin.php

 I want a login form on index.php that allows me to login with my
 username
 and password and then passes $_POST['username'] and $_POST['password']
 to
 authenticate.php

 Then authenticate.php authenticates against a database of allowed users
 (Which I already have setup and it works fine), if a valid user has
 entered the correct information then admin.php is loaded...

 header("location:admin.php");

 ...the admin.php code would look something like the following..

 Code: [Select]
 >>> if (isset($_COOKIE['username'])) {
 echo "success!";
 } else {
 echo "Failure";
 }
 ?>

 So basically I think I need to create a cookie from index.php OR
 authenticate.php and then pass the information to admin.php.
 I set the cookie like this...

 setcookie("Admin", $username);

 Which file(index.php OR authenticate.php) do I create the cookie and
 how
 do I access the information in the cookie on admin.php?


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


>>> I finally got it working. I needed to setcookie() in login.php. Also,
>>> the
>>> names of the cookies(Using setcookie()) where wrong (The names where
>>> "Admin" when they should have been "adminuser" and "adminpass") Once I
>>> fixed that then the following worked in admin.php...
>>> >> if (isset($_COOKIE['adminuser']) && isset($_COOKIE['adminpass'])) {
>>> echo "Success";
>>> } else {
>>> echo "Failed";
>>> }
>>> ?>
>>>
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>>
>>
>> You're not storing anything usable in the adminpass cookie, are you?
>> It sort of sounds like you're storing a password, or even a passhash,
>> in the cookie and you might want to rethink what that cookie contains
>> to prevent session hijacking.
>>
> Yeah, I am storing an unencrypted password in the cookie. Should I encrypt
> it, if so how, if not what should I do?
>
> I am new to programming and PHP web development so I am not aware of all
> the security problems that can occur.
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

That's an enormous question without an easy, or even a correct answer.
 I'd start by googling around for "session hijacking."  One of the
things that's probably not PC to say, is don't learn to prevent
session hijacking, learn to hijack sessions.  Once you know how to
hijack a session, you can audit your own code and fix the security
holes.

Although the best advice would probably be to find someone else's
session implementation and use that, seeing as there's no real reason
to recreate such a worn-in wheel.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Simple login form with cookies

2009-07-05 Thread Jason Carson
> On Mon, Jul 6, 2009 at 2:01 AM, Jason Carson wrote:
>>> On Mon, Jul 6, 2009 at 1:45 AM, Jason Carson
>>> wrote:
> Hello everyone,
>
> I am trying to create a PHP login script using cookies but am having
> some
> troubles. Here is my setup
>
>     index.php -> authenticate.php -> admin.php
>
> I want a login form on index.php that allows me to login with my
> username
> and password and then passes $_POST['username'] and
> $_POST['password']
> to
> authenticate.php
>
> Then authenticate.php authenticates against a database of allowed
> users
> (Which I already have setup and it works fine), if a valid user has
> entered the correct information then admin.php is loaded...
>
> header("location:admin.php");
>
> ...the admin.php code would look something like the following..
>
> Code: [Select]
>  if (isset($_COOKIE['username'])) {
> echo "success!";
> } else {
> echo "Failure";
> }
> ?>
>
> So basically I think I need to create a cookie from index.php OR
> authenticate.php and then pass the information to admin.php.
> I set the cookie like this...
>
> setcookie("Admin", $username);
>
> Which file(index.php OR authenticate.php) do I create the cookie and
> how
> do I access the information in the cookie on admin.php?
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
 I finally got it working. I needed to setcookie() in login.php. Also,
 the
 names of the cookies(Using setcookie()) where wrong (The names where
 "Admin" when they should have been "adminuser" and "adminpass") Once I
 fixed that then the following worked in admin.php...
 >>> if (isset($_COOKIE['adminuser']) && isset($_COOKIE['adminpass'])) {
 echo "Success";
 } else {
 echo "Failed";
 }
 ?>


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


>>>
>>> You're not storing anything usable in the adminpass cookie, are you?
>>> It sort of sounds like you're storing a password, or even a passhash,
>>> in the cookie and you might want to rethink what that cookie contains
>>> to prevent session hijacking.
>>>
>> Yeah, I am storing an unencrypted password in the cookie. Should I
>> encrypt
>> it, if so how, if not what should I do?
>>
>> I am new to programming and PHP web development so I am not aware of all
>> the security problems that can occur.
>>
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
> That's an enormous question without an easy, or even a correct answer.
>  I'd start by googling around for "session hijacking."  One of the
> things that's probably not PC to say, is don't learn to prevent
> session hijacking, learn to hijack sessions.  Once you know how to
> hijack a session, you can audit your own code and fix the security
> holes.
>
> Although the best advice would probably be to find someone else's
> session implementation and use that, seeing as there's no real reason
> to recreate such a worn-in wheel.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
ok, I have two sets of scripts here. One uses setcookie() for logging into
the admin panel and the other uses session_start(). Both are working fine,
is one more secure than the other?



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: best way to properly build an include path *regardless* from where I am calling the include?

2009-07-05 Thread Sudheer Satyanarayana

Govinda wrote:

On Jul 5, 2009, at 2:33 PM, Govinda wrote:


I am confusing myself reading the docs just now.

i.e.:
include_path
basename()
and dirname()

I had thought from many months ago that

would include
somefile.php
living in
somedir
regardless from where in the site structure I am calling it.

Now it does not seem to be doing that.

What is the safest (portable) way to properly build an include path 
*regardless* from where in my site I am calling the include?
If I understand right I can put includes in a dir/ specified by the 
include_path setting, but I also want to know how to do this from 
just within the root of my virtual server.


-Govinda


in my include statement, I am now successfully using:
/home/metheuser/public_html/
and am not anticipating moving this site..  but still I am thinking 
there must be a way to make the code bullet proof to dir/ name changes 
*after* the virtual server root.

Or do people just stop here?

Define a constant like APPLICATION_PATH in the bootstrap file of your 
application. Once it is defined use the paths relative to this constant. 
This way you can easily move your application around.
http://techchorus.net/constants and http://techchorus.net/include-path 
might be useful to you.




--

With warm regards,
Sudheer. S
Business: http://binaryvibes.co.in, Tech stuff: http://techchorus.net, 
Personal: http://sudheer.net


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Call to object function, want to PHP interpret returned string

2009-07-05 Thread John Allsopp

Hi

At the top of a webpage I have:

getTop("my company title");
?>

to deliver the first lines of HTML, everything in HEAD and the first 
bits of page furniture (menu, etc).


In the furniture object in getTop(), I want to return a string that 
includes the CSS file that I call with an include_once. But the 
include_once isn't interpreted by PHP, it's just outputted. So from:


   $toReturn = "Transitional//EN' 

   
   ...";

   return $toReturn;

I get



in my code.

Do I really have to break up my echo $myFurniture->getTop("my company title"); call to getTopTop, 
then include my CSS, then call getTopBottom, or can I get PHP to interpret that text that came back?


PS. I may be stupid, this may be obvious .. I don't program PHP every day

Thanks in advance for your help :-)

Cheers
J

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php