Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Cookie在Chrome中工作,但在IE或Safari中不工作?_Php_Mysql_Sql_Cookies_Browser - Fatal编程技术网

Php Cookie在Chrome中工作,但在IE或Safari中不工作?

Php Cookie在Chrome中工作,但在IE或Safari中不工作?,php,mysql,sql,cookies,browser,Php,Mysql,Sql,Cookies,Browser,我在我的登录系统中使用cookies,该系统在Chrome上工作,但当我转到IE或Safari时,它就不工作了。由于某些原因,cookies没有被设置,我尝试回显它们,但没有效果 以下是制作cookie的代码: if(isset($_POST['log_in_iniator'])){ $username = $_POST['username']; $password = $_POST['password']; $log_in_checker_status = check_

我在我的登录系统中使用cookies,该系统在Chrome上工作,但当我转到IE或Safari时,它就不工作了。由于某些原因,cookies没有被设置,我尝试回显它们,但没有效果

以下是制作cookie的代码:

if(isset($_POST['log_in_iniator'])){
    $username = $_POST['username'];
    $password = $_POST['password'];
    $log_in_checker_status = check_user_data($username, $password);
    if($log_in_checker_status == 'true'){
        //user has successfully logged in, create two cookies
        //cookie 1 username
        setcookie('username', $username, 0, 'http://shkeek.com');
        setcookie('loginstatus', 'true', 0, 'http://shkeek.com');
        header("Location: index.php");
    }else{
        setcookie('loginstatus', 'invalid', 0);
        header("Location: index.php");
    }
}
更改:

 setcookie('username', $username, 0, 'http://shkeek.com');
致:

或:(见下文)

原因:

从现在起,您将“过期”时间设置为0秒。因此,Chrome正在制作一个“会话”cookie(当你关闭浏览器时会过期),IE和FF将完全按照你告诉他们的去做——使任何匹配的cookie过期

(24*60*60)
是“一天”;24小时*60分钟*60秒

对于“域路径”部分,您只需要为当前服务器和服务器路径设置“/”

如果站点支持多个子域,请改用
'/'、'.shkeek.com'
。然后您就可以支持
www.shkeek.com
shkeek.com
img.shkeek.com
.shkeek.com
的任何其他子域

有关更多详细信息,请查看

 setcookie('username', $username, (24*60*60), '/');
 setcookie('username', $username, (24*60*60), '/', '.shkeek.com');