1

您好我正在尝试在 android 上做简单的身份验证应用程序,我使用 dreamweaver 作为编辑器。那么这里是代码,请你告诉我为什么在成功认证后我没有重定向到 login.php。

索引.html

<html><head>
<meta charset="utf-8">
<title>Guide touristique</title>
<link href="jquery.mobile.theme-1.0.min.css" rel="stylesheet" type="text/css"/>
<link href="jquery.mobile.structure-1.0.min.css" rel="stylesheet" type="text/css"/>
<script src="jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="jquery.mobile-1.0.min.js" type="text/javascript"></script>

<script language="javascript">

$(document).ready(function() {
  $("#loginform").submit(function() {
    $.post('auth.php', $(this).serialize(), function(data) { 
      $("#errorm").html(data); // semicolon missing in your code
    }); // round bracket and semicolon missing in your code
  }); // round bracket missing in your code
  return false;
}); 
</script>

</head> 
<body> 

 <div data-role="page" id="page2">
        <div data-theme="a" data-role="header">

        </div>
        <div data-role="content" style="padding: 15px">
            <div style="text-align:center">
            </div>
            <form id="loginform" method='post'>
                <div data-role="fieldcontain">
                    <fieldset data-role="controlgroup">
                        <label for="textinput2" style="text-align:right">
                           Email:
                        </label>
                        <input id="textinput2" name="login" value="" type="text"/>
                    </fieldset>
                </div>
                <div data-role="fieldcontain">
                    <fieldset data-role="controlgroup">
                        <label for="textinput3" style="text-align:right">
                            Password:                            </label>
                        <input id="textinput3" name="password" value="" type="password"/>
                    </fieldset>
                </div>     
                <h3 id="errorm"> <?php if (isset($_GET['msg'])){ 

          echo "Invalid username or password";    
 } 


 ?></h3>
                <input type="submit" name="submit" id="submit" data-inline="true" data-  icon="arrow-l" data-iconpos="left" value="login"/>
            </form>





</body>
</html>

授权文件

<?php
 //Sanitize the POST values
$login = $_POST['login'];
$password = $_POST['password'];

         $aqry="SELECT * FROM user WHERE utilisateur='".$login."' AND pswd='".$_POST['password']."'";

           $conn=mysql_query($eqry);  

    if( $conn ){
     //Check whether the query was successful or not



                  if(mysql_num_rows($conn) == 1) {
        //Login Successful

       /* $member = mysql_fetch_assoc($conn);
        $_SESSION['MEMBER_ID'] = $member['id'];
        $_SESSION['NAME'] = $member['utilisateur'];
*/

        header("location: login.php");
        exit();
        }  
                            else { 
             //Login failed 
         header("Location: mobile/mlogin.php?msg=invalid%20name%20or%20password"); 
              exit(); 
             } 
?>

登录.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>login</title>
</head>

<body>
You're logging on
</body>
</html>
4

1 回答 1

0

您正在通过带有 $.post() 的 ajax 请求进行登录,这意味着您发送的重定向正在被 ajax 请求捕获。如果您查看 FireBug 或类似的东西,您应该会看到 ajax 调用的结果实际上是 login.php。

我建议让 auth.php 始终返回一个 json 响应(请参阅http://php.net/manual/en/function.json-encode.php)类似于 {"result":"success", "redirect": "login.php"} 或 {"result":"error", "message":"abcd"}

在您的 ajax 响应处理程序中:

if (data.result == "success") {
    window.location = data.redirect;
} else {
    $("#errorm").html(data.message);
}
于 2013-05-22T18:12:28.420 回答