Jump to content

Cookie Issue - List Of Countries


intrealm

Recommended Posts

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

 

ovidiu@intelligencerealm.com

http://www.intelligencerealm.com/aisystem

Artificial Intelligence System - Reverse Engineering The Brain

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.