# Problem Reading Cookie in Internet Explorer

**URL:** https://forum.kirupa.com/t/problem-reading-cookie-in-internet-explorer/204454
**Category:** programming
**Created:** [October 19, 2006, 9:30pm UTC](https://forum.kirupa.com/t/problem-reading-cookie-in-internet-explorer/204454 "2006-10-19T21:30:58Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![rmo518](https://avatars.discourse-cdn.com/v4/letter/r/f19dbf/32.png) [@rmo518](https://forum.kirupa.com/u/rmo518)
#### Post date: [October 19, 2006, 9:30pm UTC](https://forum.kirupa.com/t/problem-reading-cookie-in-internet-explorer/204454/1 "2006-10-19T21:30:58Z")

</div>

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
<?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):  
[AS]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”);[/AS][FONT=Courier New][/FONT]

Any thoughts on how I can fix this?

---

<div class="post-metadata">

### Author: ![rmo518](https://avatars.discourse-cdn.com/v4/letter/r/f19dbf/32.png) [@rmo518](https://forum.kirupa.com/u/rmo518)
#### Post date: [October 23, 2006, 1:43pm UTC](https://forum.kirupa.com/t/problem-reading-cookie-in-internet-explorer/204454/2 "2006-10-23T13:43:26Z")

</div>

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 . . . ?

---

<div class="post-metadata">

### Author: ![rmo518](https://avatars.discourse-cdn.com/v4/letter/r/f19dbf/32.png) [@rmo518](https://forum.kirupa.com/u/rmo518)
#### Post date: [October 23, 2006, 1:51pm UTC](https://forum.kirupa.com/t/problem-reading-cookie-in-internet-explorer/204454/3 "2006-10-23T13:51:49Z")

</div>

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 . . . ?

---

<div class="post-metadata">

### Author: ![rmo518](https://avatars.discourse-cdn.com/v4/letter/r/f19dbf/32.png) [@rmo518](https://forum.kirupa.com/u/rmo518)
#### Post date: [October 25, 2006, 7:55pm UTC](https://forum.kirupa.com/t/problem-reading-cookie-in-internet-explorer/204454/4 "2006-10-25T19:55:10Z")

</div>

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
<?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'];
    }

?>

```

[AS]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”);[/AS]

I did the same thing to the buttons that set the cookie:  
[AS]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”);  
}[/AS]  
[AS]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”);  
}[/AS]
