Cookie Problem

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
speedysven
Forum Newbie
Posts: 1
Joined: Mon Jan 05, 2004 6:44 am

Cookie Problem

Post by speedysven »

I am trying to use PHP to create a cookie, I have the basic code working on my server. However, the issue arises when I try and run the code from the website the code is for. I think the issue is because the url forwards the domain to my server so the url is http://www.steverock.com but the server url is different.

Basically when I set the cookie on my server using the direct url it works fine and does everything it should, however, when I use the http://www.steverock.com url it sets a cookie but the cookie is deleted when the browser is closed.

Has anyone got any ideas on how to get round this??
Any help would be greatly appreciated.
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

You're probably setting a cookie like this:

Code: Select all

setcookie('thecookie', 'thevalue');

// but that will only last until the user closes the browsers, so u need to set the expiry time:

setcookie('thecookie', 'thevalue', time() + (60 * 60 * 24));
in that case, we added 24 hours as of the cookie was set, so it'll last for the next 24 hours.

-Nay
Post Reply