BASIC COOKIE QUESTION

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
koolsamule
Forum Contributor
Posts: 130
Joined: Fri Sep 25, 2009 10:03 am

BASIC COOKIE QUESTION

Post by koolsamule »

Hi Chaps,

I'm having trouble setting a cookie.

The login.php file is in a directory called 'account'

The cookie name in Termporary Internet Files shows as:
'account/'

instead of the standard
'cookie:user@domain.com'.
This results in the cookie being read by files with the 'account' directory.

I've searched around played around the the $path and $domain variables, but they don't seem to do anything.

Although the PHP code looks like this:

Code: Select all

setcookie($name, $value, $hour); 
The cookie looks like this:
$name, $value, $path, $time
Can someone tell me where I'm going wrong with this?
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: BASIC COOKIE QUESTION

Post by yacahuma »

why dont you use sessions?
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: BASIC COOKIE QUESTION

Post by flying_circus »

koolsamule wrote: The cookie looks like this:
$name, $value, $path, $time
Your parameter order is wrong.

http://us.php.net/manual/en/function.setcookie.php

The expiry parameter needs to be before the path parameter.
koolsamule
Forum Contributor
Posts: 130
Joined: Fri Sep 25, 2009 10:03 am

Re: BASIC COOKIE QUESTION

Post by koolsamule »

Hi,

Yeah, I know that, that's why I've coded it like:
setcookie($name, $value, $hour);
Note, I haven't put the $path variable in, however, it appears in the cookie and also the cookie (file) name is 'directory-where-login-script-is/' ????
Post Reply