Page 1 of 1

Script to place cookie works in firefox but not in Internet

Posted: Thu Aug 09, 2007 3:36 pm
by ghurty
Hello,

I have been using the following script to find out what location the user has last chosen from a drop down list.
I testing it in firefox, and everything was working great.
However, when i tried to access the page using Internet Explorer, it would not save the cookie. When every I would go back to the page it would revert to the default location (new york).
I am using IE 7 with vista, I tried it with the privacy setting at medium and at low. It didnt work either which way.

Thanks

Code: Select all

if(isset($_GET['activelocation'])){
$activelocation = $_GET['activelocation'];
setcookie('location', $activelocation, time()+60*60*24*30);
} elseif(isset($_COOKIE['location'])){
$activelocation = $_COOKIE['location']; //if the cookie is set, get the value
} else{
setcookie('location', 'New York, NY', time()+60*60*24*30);
$activelocation = "New York, NY";
}

Posted: Fri Aug 10, 2007 5:45 am
by volka
please try

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors', true);

if( isset($_GET['activelocation']) ){
  $activelocation = $_GET['activelocation'];
  $ts = time()+60*60*24*30;
  setcookie('location', $activelocation, $ts);
  echo '<div>Debug: ', $activelocation, ' ', gmdate('r', $ts), "</div>\n";
} elseif( isset($_COOKIE['location']) ){
  $activelocation = $_COOKIE['location']; //if the cookie is set, get the value
  echo '<div>Debug: got', $activelocation, "</div>\n";
} else{
  $ts = time()+60*60*24*30;
  setcookie('location', 'New York, NY', $ts);
  echo '<div>Debug: default ', gmdate('r', $ts), "</div>\n";
  $activelocation = "New York, NY";
}