原因未知,登錄表單無法在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> </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 Reference和MDN),無type
屬性按鈕標籤,因爲Safari瀏覽器1.0的支持。因此,我試圖將其更改爲<input type="submit" value="Login" />
,但Safari仍拒絕工作(重定向到沒有任何消息的同一頁面)。
我還看到了什麼?
注意:沒有在Safari中檢測/顯示的問題。沒有控制檯消息。該頁面也通過了W3C HTML驗證。
請定義「不工作」。這是否意味着按鈕不提交表單? – deceze 2013-02-28 08:32:52
它提交表單,但重定向到同一頁面,沒有任何錯誤消息 – Raptor 2013-02-28 08:35:42
這個頁面是index.php頁面嗎? – George 2013-02-28 08:39:04