Trouble redirecting after cookie is sent

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
jestep
Forum Newbie
Posts: 4
Joined: Fri Jan 30, 2004 11:38 am

Trouble redirecting after cookie is sent

Post by jestep »

Im trying to redirect to a different page depending on whether or not the user has a cookie that was sent to them on a different page.

Here is the Cookie:

<?php
setcookie("affiliate", "washere", time()+60*60*24*30, "/", "merchantequip.com");
?>

Here is the redirect script:

<?php
//If no cookie redirect
if ($_COOKIE["affiliate"] == "washere") {
echo("<meta http-equiv='refresh' content='0;url=sales.php'>");
}else{
if ($_COOKIE["affiliate"] != "washere") {
echo("<meta http-equiv='refresh' content='0;url=sales2.php'>");
}
}
?>

It always redirects to the sales2.php page and I need it to redirect to the sales.php page if the user has the cookie.

Code: Select all

<?php

?>
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Does affiliate appear in a var_dump($_COOKIE); ?
If not then it looks as though the cookie isn't being set.
jestep
Forum Newbie
Posts: 4
Joined: Fri Jan 30, 2004 11:38 am

Post by jestep »

I did a test and found that I am unable to send the cookie at all, I looked through the forum and tried about 10 different methods to test if the cookie was being sent, nothing seems to work.

Im not sure how to use the var_dump($_COOKIE); function, but it sounds like it might be the problem.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

From the manual......

Cookies will not become visible until the next loading of a page that the cookie should be visible for. To test if a cookie was successfully set, check for the cookie on a next loading page before the cookie expires. Expire time is set via the expire parameter. A nice way to debug the existence of cookies is by simply calling print_r($_COOKIE);.
jestep
Forum Newbie
Posts: 4
Joined: Fri Jan 30, 2004 11:38 am

Post by jestep »

tried the print_r($_COOKIE);.
no cookies come up,
Cookies are enabled in my browser, and I can see them in my temp folder
Post Reply