When I try to setup cookie with php. (in test environment)

$cookiedomainname = 'localhost';

setcookie("testcookiename", 'testnumber', time()+1*24*3600, "/", $cookiedomainname);

echo $testcookiename;

It works on Firefox and Chrom, but it not works on IE8;

But when I upload file to real server (a real server, have a domainname, xxxx is example donamein address)

$cookiedomainname = 'xxxx.com';

setcookie("testcookiename", 'testnumber', time()+1*24*3600, "/", $cookiedomainname);

echo $testcookiename;

It all works on Firefox, Chrome and  IE8;

 

I guess the reason is IE8 have problem with cookie domain name setting.

Maybe it has too high security verify, when it found domain name is hot the same with cookiedomainname.

especially "localhost" seems not accepted on IE8 cookie setting;

However, "xxxx.com" is fine on IE8 when you upload to real server.

 

 

Here is the soluting:

(1) don't care about localhost (test environment), just upload file to real server. In real server, domain is equal to cookie domain setting, IE8 will work correct.

(2) if you still want php works on localhost environment. please remove domina setting on PHP.

do not use : setcookie("testcookiename", 'testnumber' ,time()+1*24*3600, "/", $cookiedomainname);

use this: setcookie("testcookiename", 'testnumber', time()+1*24*3600, "/");

 

arrow
arrow
    全站熱搜

    Chung 發表在 痞客邦 留言(0) 人氣()