Script to place cookie works in firefox but not in Internet

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ghurty
Forum Newbie
Posts: 1
Joined: Thu Aug 09, 2007 3:34 pm

Script to place cookie works in firefox but not in Internet

Post 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";
}
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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";
}
Post Reply