我的登录表单不适用于Chrome

时间:2011-03-03 16:51:54

标签: php html forms google-chrome

我已经使用IE和Firefox进行了测试,但在Chrome上我的登录表单根本不会响应。没有错误消息,没有任何东西它只是没有做任何事情。

以下是代码:

<form action="process.php" method="POST">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr><td>Username:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?></td></tr>
<tr><td colspan="2" align="left"><input type="checkbox" name="remember" <? if($form->value("remember") != ""){ echo "checked"; } ?>>
<font size="2">Remember me next time &nbsp;&nbsp;&nbsp;&nbsp;
<input type="hidden" name="sublogin" value="1">
<input type="submit" value="Login"></td></tr>
</table>
</form>

process.php:

   function procLogin(){
      global $session, $form;
      /* Login attempt */
      $retval = $session->login($_POST['user'], $_POST['pass'], isset($_POST['remember']));

      /* Login successful */
      if($retval){
         header( 'Location: index.php' ) ;
      }
      /* Login failed */
      else{
         $_SESSION['value_array'] = $_POST;
         $_SESSION['error_array'] = $form->getErrorArray();
         header("Location: ".$session->referrer);
      }
   }

session.php文件:

function login($subuser, $subpass, $subremember){
      global $database, $form;  //The database and form object

      /* Username error checking */
      $field = "user";  //Use field name for username
      if(!$subuser || strlen($subuser = trim($subuser)) == 0){
         $form->setError($field, "* Username not entered");
      }
      else{
         /* Check if username is not alphanumeric */
         if(!eregi("^([0-9a-z])*$", $subuser)){
            $form->setError($field, "* Username not alphanumeric");
         }
      }

      /* Password error checking */
      $field = "pass";  //Use field name for password
      if(!$subpass){
         $form->setError($field, "* Password not entered");
      }

      /* Return if form errors exist */
      if($form->num_errors > 0){
         return false;
      }

      /* Checks that username is in database and password is correct */
      $subuser = stripslashes($subuser);
      $result = $database->confirmUserPass($subuser, md5($subpass));

      /* Check error codes */
      if($result == 1){
         $field = "user";
         $form->setError($field, "* Username not found");
      }
      else if($result == 2){
         $field = "pass";
         $form->setError($field, "* Invalid password");
      }

      /* Return if form errors exist */
      if($form->num_errors > 0){
         return false;
      }

      /* Username and password correct, register session variables */
      $this->userinfo  = $database->getUserInfo($subuser);
      $this->username  = $_SESSION['username'] = $this->userinfo['username'];
      $this->userid    = $_SESSION['userid']   = $this->generateRandID();
      $this->userlevel = $this->userinfo['userlevel'];

      /* Insert userid into database and update active users table */
      $database->updateUserField($this->username, "userid", $this->userid);
      $database->addActiveUser($this->username, $this->time);
      $database->removeActiveGuest($_SERVER['REMOTE_ADDR']);

      if($subremember){
         setcookie("cookname", $this->username, time()+COOKIE_EXPIRE, COOKIE_PATH);
         setcookie("cookid",   $this->userid,   time()+COOKIE_EXPIRE, COOKIE_PATH);
      }

      /* Login completed successfully */
      return true;
   }

3 个答案:

答案 0 :(得分:1)

我在使用jpWare时遇到了同样的问题,这是你的代码所基于的。

当您在一个浏览器上使用“记住我”功能,然后在其他浏览器上登录时,会出现问题。这是因为php试图使用过时的cookie中存储的数据来验证你的sessionId。

要解决此问题,PHP会在登录时删除这些cookie。如下所示:

  /* Insert userid into database and update active users table */
  $database->updateUserField($this->username, "userid", $this->userid);
  $database->addActiveUser($this->username, $this->time);
  $database->removeActiveGuest($_SERVER['REMOTE_ADDR']);

    if($subremember){
        setcookie(COOKIE_NAME, $this->customer_id, time()+COOKIE_EXPIRE, COOKIE_PATH);
        setcookie(COOKIE_ID,   $this->session_id,   time()+COOKIE_EXPIRE, COOKIE_PATH);
    } else {
    /* Delete cookies - This fixes a bug that wouldn't let you log in if your
     * session_id got changed (by another browser for example) but your cookies
     * still referenced the old one.
     */
    setcookie(COOKIE_NAME, $this->customer_id, time(), COOKIE_PATH);
    setcookie(COOKIE_ID,   $this->session_id,   time(), COOKIE_PATH);}

答案 1 :(得分:0)

首先尝试为你的按钮分配一个“名字”,然后在你的process.php中,检查是否按下了这个按钮,然后检查其他所有内容......检查应该是这样的:

if(isset($_POST['submit_name'])){

}

答案 2 :(得分:0)

表格中的每一行必须具有相同数量的td:s。 由于前两行有3个单元格,因此colspan的最后一行也必须有3个。