intrealm Posted November 20, 2007 Share Posted November 20, 2007 Hi there, I have a bit of an issue setting the cookie for a page. I have an entry page that displays a list of countries and after the user selects one from the combobox I would like to store the user's choice in a cookie so that it doesn't have to go through the same process, when he/she is returning to the site and also to use the country name when displaying content on some other pages of the site. I can see the cookie in FireFox, in IE I can't see it, but it doesn't work. It keeps displaying the page like there is no cookie. I have tried whatever methods I found, setting the cookie with JavaScript, and some other ones I saw on the comments listed under php documentation page but without success. I am running Apache and PHP and I am converting the site from ASP. Here is the source code and the files: country.inc ---------------------------------------------------------- <?php function get_country_name($country_folder) { $country_name = ''; if ($country_folder != '') { if ($country_folder == 'Aruba') $country_name = 'Aruba'; if ($country_folder == 'Antartica') $country_name = 'Antartica'; // .......................... (list of countries) .................... } return $country_name; } ?> index.php ---------------------------------------------------------- <?php if (session_id() == "") session_start(); // check if there is a session and if it isn"t, start one // initialize variables $URL = "http://www.intelligencerealm.com/"; if (isset($_COOKIE["Country"])) { $country = $_COOKIE["Country"]; $country_folder = substr($country, 1); // remove cookie if found - it was used on the old ASP web site setcookie("Country", $country, time()-60*60*24, "/", ".intelligencerealm.com", 1); } else { if (isset($_COOKIE["CountryFolder"])) $country_folder = $_COOKIE["CountryFolder"]; else $country_folder = ""; } if ($country_folder != "") { $_SESSION["CountryFolder"] = $country_folder; $_SESSION["CountryName"] = ""; $URL = $URL . "session.php?CountryFolder=" . $country_folder; } else { // default country $country_folder = "Canada"; $country_name = "Canada"; $_SESSION["CountryFolder"] = $country_folder; $_SESSION["CountryName"] = $country_name; $URL = $URL . "index_ie.php"; } } $URL = "Location: " . $URL; // cookie will expire in 7 years setcookie("CountryFolder", $country_folder, time()+60*60*24*30*12, "/", ".intelligencerealm.com", 1); header($URL); // redirect to URL exit; ?> session.php ---------------------------------------------------------- <?php require_once("country.inc"); session_start(); // initialize variables $URL = 'http://www.intelligencerealm.com/'; $country_name = ''; // retrieve QueryString value $country_folder = $_GET['CountryFolder']; if ($country_folder != '') { $country_name = get_country_name($country_folder); $_SESSION['CountryFolder'] = $country_folder; $_SESSION['CountryName'] = $country_name; $URL = $URL . 'Countries/Local/index.php?CountryFolder=' . $country_folder; } $URL = 'Location: ' . $URL; header($URL); // redirect to URL exit; ?> Any help on how to do that would be greatly appreciated. Thank you very much. Best regards, Ovidiu Anghelidi [email protected] http://www.intelligencerealm.com/aisystem Artificial Intelligence System - Reverse Engineering The Brain Link to comment https://forums.phpfreaks.com/topic/78089-cookie-issue-list-of-countries/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.