I've been attempting to figure this out for a little while now, and it's driving me nuts. Basically I have a form for US and Canadian users. There's a link at the bottom of the form for Canadian users, which directs users to can-sesssion.php, which contains:
<?php
if (isset($_SESSION['can'])) {
session_start();
session_destroy();
session_unset();
session_start();
$_SESSION['can'] = 2;
}
else {
session_start();
$_SESSION['can'] = 1;
}
header('Location: '. $_SERVER['HTTP_REFERER'] . '');
?>
Basically, if they click on the link, it sets $_SESSION['can'] = 1. Now There's another option, and if they click that link, it takes them back to this page, and the session should be destroyed and a new value is set (well, that's what it's supposed to do). Problem is, I've printed out $_SESSION['can'], and it's still retaining that old value after going to that page. Is there a better way to do this, or is there something wrong w/ my code? Thanks for the help.
HTTP_REFERERis not a header you can rely on being set, or being set to the actual referring page. It is optional and the browser can send whatever it wants.