cookie does not get saved

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
thosecars82
Forum Commoner
Posts: 94
Joined: Thu Apr 03, 2008 6:31 am
Location: Arganda, Madrid
Contact:

cookie does not get saved

Post by thosecars82 »

hello there
I am creating a cookie with php which actually does exist because I can check it in the opera browser for example:tools-preferences-advanced-cookies-manage cookies. The cookie does not get saved for next time I open the browser though. Do you know how to fix this?
The example is for a cookie which remembers the language in http://www.metatradersoftware.com. May be you can check with your browsers what I mean.
Thanks in advance
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: cookie does not get saved

Post by panic! »

you need to set a time limit on the cookie.

Code: Select all

setcookie('yourname','steve',time()+3600);
will expire after an hour.

Code: Select all

setcookie('yourname','steve',time()+86400);
will expire after a day
thosecars82
Forum Commoner
Posts: 94
Joined: Thu Apr 03, 2008 6:31 am
Location: Arganda, Madrid
Contact:

Re: cookie does not get saved

Post by thosecars82 »

panic! wrote:you need to set a time limit on the cookie.

Code: Select all

setcookie('yourname','steve',time()+3600);
will expire after an hour.

Code: Select all

setcookie('yourname','steve',time()+86400);
will expire after a day
Thks for that effective reply.
thosecars82
Forum Commoner
Posts: 94
Joined: Thu Apr 03, 2008 6:31 am
Location: Arganda, Madrid
Contact:

Re: cookie does not get saved

Post by thosecars82 »

thosecars82 wrote:
panic! wrote:you need to set a time limit on the cookie.

Code: Select all

setcookie('yourname','steve',time()+3600);
will expire after an hour.

Code: Select all

setcookie('yourname','steve',time()+86400);
will expire after a day
Thks for that effective reply.
Guess what's the problem now?
I get this message:
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\pruebalocal1\metatradersoftwarecaca\anexos\header.php:8) in C:\xampp\htdocs\pruebalocal1\metatradersoftwarecaca\anexos\header.php on line 159
Does anybody know how to avoid that the setcookie function throw this warning?
Thanks in advance
thosecars82
Forum Commoner
Posts: 94
Joined: Thu Apr 03, 2008 6:31 am
Location: Arganda, Madrid
Contact:

Re: cookie does not get saved

Post by thosecars82 »

thosecars82 wrote:
thosecars82 wrote:
panic! wrote:you need to set a time limit on the cookie.

Code: Select all

setcookie('yourname','steve',time()+3600);
will expire after an hour.

Code: Select all

setcookie('yourname','steve',time()+86400);
will expire after a day
Thks for that effective reply.
Guess what's the problem now?
I get this message:
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\pruebalocal1\metatradersoftwarecaca\anexos\header.php:8) in C:\xampp\htdocs\pruebalocal1\metatradersoftwarecaca\anexos\header.php on line 159
Does anybody know how to avoid that the setcookie function throw this warning?
Thanks in advance
solved
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: cookie does not get saved

Post by panic! »

glad to be of service.
Post Reply