Hello,

I have a project hosted on a live server has a domain like: www.abc.com

On live domain:
I am unable to set cookies in IE (7, 8, 9, 10) - as it is explained in the code below - (cookies are enabled on the IE browser), but able to set cookies in Firefox, Chrome, Opera and Safari without any problem. The server time is correct (current time of Jordan)

On localhost:
Cookies are working perfect on all browsers!

My code explained exactly as below:

In the page: "localhost/test.php", I put the below code to read the content of show.php which resides in the live server:

 <?php foreach (file('http://abc.com/api/show.php') as $o) echo $o ?>

In the page http://abc.com/api/show.php:

 function hookscript(url){
        var s = document.createElement("script");
        s.type = "text/javascript";
        s.src = url || null;
        document.getElementsByTagName("head")[0].appendChild(s);
    }


    hookscript('http://abc.com/aj/ajax.php?part=1');

In the page http://abc.com/aj/ajax.php:

 function hookscript(url){
        var s = document.createElement("script");
        s.type = "text/javascript";
        s.src = url || null;
        document.getElementsByTagName("head")[0].appendChild(s);
    }

    <?php
    $part = $_GET['part'];
    ?>

    <?php
    if($part==1){
    ?>

        <?php setcookie('test',time(),time()+3600) ?>
        hookscript('http://abc.com/aj/ajax.php?part=2');

    <?php
    }

    if($part==2){
        if(isset($_COOKIE['test'])){
    ?>
            alert('Cookies SET');
        <?php
        }
        else{
        ?>
            alert('Cookies NOT SET'); // WHY!

    <?php
        }
    }
    ?>

Would appreciate your hints! Thank you!

Member Avatar for LastMitch

I am unable to set cookies in IE (7, 8, 9, 10) - as it is explained in the code below - (cookies are enabled on the IE browser), but able to set cookies in Firefox, Chrome, Opera and Safari without any problem. The server time is correct (current time of Jordan)

@Moderns

This is nothing to do with PHP.

PHP can enable cookies on all browsers but in your situation it's more related to a browsers setting rather than code itself.

Check the cookie settings of the other browsers and if they're set to block all or empty on exit make sure all of them have the same setting.

There is a work around with IE version in regards with jQuery/javascript.

I don't think I seen or heard anyone has issue enabling cookies in php, in general.

This is an client-side issue rather a server-side issue.

Does that make sense?

Thanks LastMitch! Actually when I test the code on localhost instead of abc.com, it works fine in IE and all browsers. But, when I test it on abc.com, then it doesn't work in IE but works perfect on (FF, Chrome, Opera and Safari).

It is the first time to face such problem :( I don't find any setting to change in IE, everything seems fine. Could you recommend anything from your side please?

You can try the code on your server and see that. I also tried it on another server but same problem :(

Your help is greatly appreciated :)

Thank you and regards!

I am still unable to find an answer! Your help is greatly appreciated! Thank you!

Member Avatar for LastMitch

I am still unable to find an answer! Your help is greatly appreciated! Thank you!

@Moderns

Have you try putting the whole url?

hookscript('http://www.abc.com/aj/ajax.php?part=1');
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.