Forum Moderators: coopster

Message Too Old, No Replies

After Setting the Cookie How Do I Redirect It to Another Page

How do I redirect a page after I verify a cookie

         

creativeramsey

12:45 am on Jul 3, 2009 (gmt 0)

10+ Year Member



There is the index page and then a list of cities, you click on the city and it sets this cookie;

<?php
setcookie('city', 'fresno', time(360000)); ?>

it sets this cookie on the fresno.php page, now what i need is an if statement on the index page that says if the cookie's value is 'fresno' then it will redirect to fresno.php?
Any goes?

bkeep

3:15 am on Jul 3, 2009 (gmt 0)

10+ Year Member



Something like this should get you started

if (isset($_COOKIE["city"])) {
if ($_COOKIE["city"] == 'fresno') {
header("Location: fresno.php");
}
}

creativeramsey

3:20 am on Jul 3, 2009 (gmt 0)

10+ Year Member



now after I set that, i duplicate it but the code doesnt show up

creativeramsey

3:34 am on Jul 3, 2009 (gmt 0)

10+ Year Member



ok i have it all fixed this is what i have....

<?php
if (isset($_COOKIE["city"])) {
if ($_COOKIE["city"] == 'fresno') {
header("Location: fresno.php");
}
}
if (isset($_COOKIE["city"])) {
if ($_COOKIE["city"] == 'oakland') {
header("Location: oakland.php");
}
}
?>

but now i need a way for them to go back to the index page so they can delete the cookie if you will so they choose another city

omoutop

1:10 pm on Jul 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



at your index page just delete any existing cookies

if (isset($_COOKIE["city"]))
{
setcookie('city', '', 10);
header("Location: index.php");

}