2013-02-28 56 views
1

原因未知,登錄表單無法在Safari中工作(從5.1.x到最新版本)。儘管與其他瀏覽器一起工作。Safari:表單提交

的完整代碼(網頁是的index.php

<?php 
ini_set('display_errors', '1'); 
$err = ''; 
if(isset($_POST['action']) && $_POST['action'] == 'login') { 
    require_once('require_once.php'); 
    $ans = Core::Authenticate($_POST['txt_user'], $_POST['txt_pass']); 
    if($ans) { 
     session_set_cookie_params(3600, domain_path); 
     session_start(); 
     $_SESSION['login_key'] = 'A COMPLEX LOGIC'; 
     header('Location: console.php'); 
     exit; 
    } else { 
     $err = 'Invalid Username/Password'; 
    } 
} 
?> 
<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8" /> 
    <title>Login</title> 
    <link rel="stylesheet" type="text/css" href="css/style.css" /> 
</head> 
<body> 
    <div id="login_wrapper"> 
     <form action="index.php" method="post"> 
     <input type="hidden" name="action" value="login" /> 
     <h1>Welcome</h1> 
    <?php 
    if($err != '') { 
     echo '<p>Error: ' . $err . '</p>' . PHP_EOL; 
    } 
    ?> 
       <table class="tbl_login"> 
      <tr> 
       <td>Username</td> 
       <td><input type="text" name="txt_user" /></td> 
      </tr> 
      <tr> 
       <td>Password</td> 
       <td><input type="password" name="txt_pass" /></td> 
      </tr> 
      <tr> 
       <td>&nbsp;</td> 
       <td><button>Login</button></td> 
      </tr> 
     </table> 
     </form> 
    </div> 
</body> 
</html> 

Core::Authenticate是,如果憑證匹配,返回true的功能。

require_once.php包含其他所需文件,如配置文件,DB庫等

domin_path是腳本的絕對路徑,在全球範圍內定義。

我不認爲這是服務器端的錯誤,因爲其他瀏覽器(Chrome,IE,Firefox)的工作。

我懷疑這是由於<button>標籤,但是當我擡頭的文件(從Safari HTML ReferenceMDN),無type屬性按鈕標籤,因爲Safari瀏覽器1.0的支持。因此,我試圖將其更改爲<input type="submit" value="Login" />,但Safari仍拒絕工作(重定向到沒有任何消息的同一頁面)。

我還看到了什麼?

注意:沒有在Safari中檢測/顯示的問題。沒有控制檯消息。該頁面也通過了W3C HTML驗證。

+0

請定義「不工作」。這是否意味着按鈕不提交表單? – deceze 2013-02-28 08:32:52

+0

它提交表單,但重定向到同一頁面,沒有任何錯誤消息 – Raptor 2013-02-28 08:35:42

+0

這個頁面是index.php頁面嗎? – George 2013-02-28 08:39:04

回答

5

終於找到了Safari無法提交表單的原因。

不知何故domain_path設置不正確。它不包含領先的/。更正域路徑後,功能session_set_cookie_params()正常工作。

但爲什麼其他瀏覽器工作正常?

+0

檢查此答案,如果您使用javascript創建cookie:http://stackoverflow.com/a/5671466/1136132 – joseantgv 2015-09-29 17:21:42

+0

很好的參考,但您所指的答案不是Safari特定的。好吧,也許它在這兩年後是固定的。讓我稍後重試該方案。 – Raptor 2015-09-30 02:06:22

+0

我昨天剛剛在Safari(5.1.7版 - 最後一個Windows穩定版)上遇到了這個問題,所以它還沒有被修復!你的解決方案完美無缺:) – joseantgv 2015-09-30 06:38:32