2013-02-28 58 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