Possible Duplicate:
Cookies aren't persisting in PHP?
My objective is: when a user visits my website landing page and chooses their city (x or y), I would like to set a cookie that remembers this choice, so next time they visit the landing page it redirects straight to their city. The code I currently have is this:
landing page:
<?php
if (isset($_COOKIE['cambridge'])) {
header('Location: http://cambridge.guestvibe.com');
}
else if (isset($_COOKIE['oxford'])) {
header('Location: http://oxford.guestvibe.com');
}
?>
city-specific page (one example):
<?php setcookie("Cambridge",""); ?>
I've also tried:
<?php setcookie("Cambridge",""); ?>
This isn't working for me but it's my first time working with cookies. Any idea what's wrong?
EDIT
The accepted answer solves half the problem, but for WordPress it's also necessary to add some code, explained here.
Final code is:
setcookie('city','Cambridge',time()+86400*365, "/", ".guestvibe.com");