PDA

View Full Version : Problem Reading Cookie in Internet Explorer



rmo518
October 19th, 2006, 05:30 PM
I have a php script that I call from a Flash movie to set a cookie. The purpose of this cookie is to have the sound turned on or off as a person moves through the site. Everything works fine in FireFox, but in Internet Expolorer (version 6.0.2800.1106 for what it's worth) it won't recognize the cookie until I close IE and open it again - then it does recognize it.

Here's my code:

<?php
$expire = time() + (60*60*24*365*10);
if($_GET['mode'] == 1){
//Sound on
setcookie("audioCookie", 1, $expire, "/", ".mydomain.com", false);
print 'sound=1&setting';
} else if($_GET['mode'] == 0){
// Sound off
setcookie("audioCookie", 0, $expire, "/", ".mydomain.com", false);
print 'sound=0&setting';
} else {
// Checking status
print 'sound='.$_COOKIE['audioCookie'];
}
?> To check the status I use the following AS (In case it matters, I'm working in Flash MX):
audioVars = new LoadVars();
sendVars = new LoadVars();
sendVars.mode = 3;
audioVars.onLoad = function() {
_root.soundCheck = audioVars.sound;
if (audioVars.sound == "0") {
sound_mc.gotoAndStop(2);
}
};
sendVars.sendAndLoad("sound.php", audioVars, "GET");

Any thoughts on how I can fix this?

rmo518
October 23rd, 2006, 09:43 AM
Bump . . .

I'm pretty sure my AS is not the problem. But for some reason IE won't recognize the cookie until I close the browser and re-open it.

Anyone . . . ?

rmo518
October 25th, 2006, 03:55 PM
Well, I got it working in IE. I added a variable named rnd (a random number) that evidently forces IE to take a 'fresh look' at the cookie. Here's the code I ended up with:

<?php
$expire = time() + (60*60*24*365*10);
if($_GET['mode'] == 1){
//Sound on
setcookie("audioCookie", 1, $expire, "/", ".mydomain.com", false);
print 'sound=1&setting';
} else if($_GET['mode'] == 0){
// Sound off
setcookie("audioCookie", 0, $expire, "/", ".mydomain.com", false);
print 'sound=0&setting';
} else {
// Checking status
print 'sound='.$_COOKIE['audioCookie'];
}

?>

audioVars = new LoadVars();
sendVars = new LoadVars();
sendVars.mode = 3;
sendVars.rnd = Math.round(Math.random()*100000);
audioVars.onLoad = function() {
_root.soundCheck = parseInt(audioVars.sound);
if (_root.soundCheck < 1) {
sound_mc.gotoAndStop(2);
}
};
sendVars.sendAndLoad("sound.php", audioVars, "GET");

I did the same thing to the buttons that set the cookie:
on(release){
gotoAndStop(2);
audioVars = new LoadVars();
sendVars = new LoadVars();
sendVars.mode = 0;
sendVars.rnd = Math.round(Math.random()*100000);
sendVars.sendAndLoad("sound.php", audioVars, "GET");
}
on(release){
gotoAndStop(1);
audioVars = new LoadVars();
sendVars = new LoadVars();
sendVars.mode = 1;
sendVars.rnd = Math.round(Math.random()*100000);
sendVars.sendAndLoad("sound.php", audioVars, "GET");
}