Safari browser not handling cookie - PHP

2019-07-09 04:02发布

问题:

I am stuck on this problem for the last two days, I Have the following code in my main "login.php" file Which is running in all browsers without any problem, but not in "Safari".

 if(isset($_SESSION["del_log"]) && !empty($_SESSION["del_log"]) && isset($_SESSION["user_type"]) && !empty($deal_type)){

            $expire=time()+60*60*24*365;
            setcookie("del_log",$_SESSION["del_log"], $expire, '/');
            setcookie("user_type", $_SESSION["user_type"], $expire, '/');

    echo "<script>window.location.href=\"http://www.sample.com/foldername/index.php\"</script>";
        }

i am checking these cookies in ".../foldername/index.php" file as:

 if (isset($_COOKIE["del_log"]) && !empty($_COOKIE["del_log"])){
     $log=$_COOKIE["del_log"];
     $user_type=$_COOKIE["user_type"];
 }else{
     echo "<script>window.location.href=\"http://www.sample.com/\"</script>";
 }

回答1:

Encounter this issue before. The session's cookie path ( http://php.net/manual/en/function.session-set-cookie-params.php ) must have a trailing slash in order to work. Safari specific.

See my another question's answer: https://stackoverflow.com/a/15131791/188331



标签: php safari