由于未知原因,登录表单无法在Safari中工作(从5.1.x到最新版本)。不过可以与其他浏览器配合使用。
完整代码(页面为
索引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
和
MDN
),按钮标签,不带
type
自Safari 1.0以来,支持属性。因此,我尝试将其更改为
<input type="submit" value="Login" />
,但Safari仍然拒绝工作(在没有任何消息的情况下重定向到同一页面)。
我还看错了什么?
注意:Safari中未检测到/显示任何问题。也没有控制台消息。该页面也通过了W3C HTML验证。