2013-04-12 104 views
2

我被困在這個問題上的最後兩天, 我在我的主「login.php」文件中有以下代碼 這是在所有瀏覽器中運行沒有任何問題,但沒有在「Safari」中。Safari瀏覽器不處理cookie - PHP

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>"; 
     } 

我在 「... /文件夾名/ index.php」 包含文件檢查這些cookie爲:本次發行前

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>"; 
} 
+0

它設置cookie的,不讀或不設置呢? – Voitcus

+0

它不設置cookie ... –

回答

1

遭遇。會話的cookie路徑(http://php.net/manual/en/function.session-set-cookie-params.php)必須有一個結尾斜槓才能工作。特定於Safari。

見我的另一個問題的回答是:https://stackoverflow.com/a/15131791/188331

+1

我自己在這個問題上花費了相當多的時間。這個答案是正確的,但我想添加的問題不僅僅是Safari專用的; iOS上的Chrome瀏覽器的行爲方式相同。 – rick6

+0

iOS上的Chrome基本上是Safari。沒有什麼不同。只是一個不同的皮膚。 –

+0

@CalebPrenger你如何得出這個結論?非常錯誤。 – Raptor