PDA

View Full Version : Set Cookie and Redirection


Moonlight
01-03-2000, 09:47 AM
I'm trying to create some cookies and after creating the cookies, to redirect the user to another page.

It will be used in the Login and Logout scripts.

I have the following :
SetCookie("TOGRCLID",$Acc_ID,time()*3600*6,"/bguilds/",".togrc.com");
SetCookie("TOGRCLPwd",$Acc_Password,time()*3600*6,"/bguilds/",".togrc.com");
header("Location: http://www.togrc.com/bguilds/\n\n");


The above example would not create any cookies but would do the redirect.

If I remove the header statement, then the cookies would be created.

What should I do?

Thanks,

Moonlight
[This message has been edited by Moonlight (edited 01-03-00@09:48 am)]

Justin
01-03-2000, 10:05 AM
There are a couple of isues...

First, you are setting the expire date to time() * 3600 * 6... that's a long long time...

time() returns the Unix time stamp - number of seconds since 1970. Setcookie() requires that same time stamp. So passing time() tells it to expire now. Passing time() + 86400 tells it to expire in 24 hours. Passing time() * 3600 * 6 probably causes an overflow ;)

If you are going for 6 days, try using time() + (86400 * 6) or multiply that out manually first... either way...

Second issue - the header() function does not need the newlines - you should not print them manually. Remember, this is PHP, not Perl (I do that a lot myself)...

Hope this helps...

------------------
Justin Nelson
FutureQuest Support

Moonlight
01-03-2000, 10:11 AM
It seems that, in that particular place, I replaced a + by a *. All of my other cookies have a +. Now... I wonder in what centuries my cookies would have expired.

I removed the \n\n and it all works as it should.

Thanks Justin.

Moonlight

[This message has been edited by Moonlight (edited 01-03-00@10:11 am)]