由于未知原因,登录表单无法在 Safari 中工作(从 5.1.x 到最新版本)。虽然适用于其他浏览器。
完整代码(页面为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
包含其他必需的文件,例如配置文件、数据库库等。
domin_path
是脚本的绝对路径,在全局范围内定义。
我不认为这是服务器端错误,因为其他浏览器(Chrome、IE、Firefox)都可以工作。
我怀疑这是由于<button>
标签造成的,但是当我查找文档(来自Safari HTML Reference和MDNtype
)时,自 Safari 1.0 起支持不带属性的按钮标签。因此,我尝试将其更改为<input type="submit" value="Login" />
,但 Safari 仍然拒绝工作(重定向到同一页面而没有任何消息)。
我还看错了什么?
注意:在 Safari 中未检测到/显示任何问题。也没有控制台消息。该页面也通过了 W3C HTML 验证。