cookies

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
User avatar
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

cookies

Post by elecktricity »

for some reason the cookies dont seem to be working, they work like this, you log in it sets 2 cookies 1 cookie named 'user' with your username the other 'pass' with your password, on the header of each page it queries the database and if the username and password match up the itll display some stuff the you can edit/check/ect and the such, for some reason it only works on the button.php page all the other pages wont work...

normal pages look something like this:

Code: Select all

<?PHP
include('header.php');
echo 'stuff here';
include('footer.php');
?>
the cookie depends on a checkbox hour or month

Code: Select all

<?PHP
//most stuff at the top
if ($length=='hour') {
setcookie ('user', $user, time()+3600, '', '', 0);
setcookie ('pass', $pass, time()+3600, '', '', 0);
}
else {
setcookie ('user', $user, time()+2592000, '', '', 0);
setcookie ('pass', $pass, time()+2592000, '', '', 0);
}
//more stuff down here
?>
this only seems to work on the 'button.php' page, im not sure how his is working... but I decided to try and echo a few things out and the cookies dosnt seem to be working at all except on that page anybody know whats up... I may just have think of a new way to do this, by like encrypting an variable with the user/pass/expire and such like that kind of thing
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

You might want to set the path and domain and see what happens.

Code: Select all

$path = '/';
$domain = 'yourdomain.com';
setcookie ('user', $user, time()+2592000, $path, $domain, 0);
setcookie ('pass', $pass, time()+2592000, $path, $domain, 0);
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Try var_dump($_COOKIE).

You've probably aready checked but ...

Are your sure $user and $passwd isset to something.
User avatar
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

Post by elecktricity »

well it dosnt seem to be any of those... I have been doing some testing, the header.php works when your directly at the page, which we really dont want, and I tried echoing the cookies and stuff they only work on the pages your on... not like included pages, so im thinking I need to just add a bit of something to other pages and try and get this to work

I am absolutely 100% unsure how this works, why some variables or cookie cannot be passed through included pages, when sometimes it does work on certain pages, if somebody has some insight that would be greatly appreciated thanks.
Post Reply