2013-05-21 18 views
1

你好我正在嘗試在android上做簡單的認證應用程序,我使用dreamweaver作爲編輯器。那麼這裏是代碼,請告訴我爲什麼在成功驗證後我沒有重定向到login.php。使用php/html/jquery進行手機驗證

的index.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> 

auth.php

<?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(); 
      } 
?> 

的login.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> 

回答

0

您通過使用$。員額一個Ajax請求做登錄()這意味着您發送的重定向正被ajax請求捕獲。如果你看看FireBug或類似的東西,你應該看到ajax調用的結果實際上是login.php。

我建議讓auth.php總是返回一個類似於{「result」:「success」,「redirect」:「login.php」}或{「result」:「error的json響應(請參閱http://php.net/manual/en/function.json-encode.php) 」, 「消息」: 「ABCD」}

在你的Ajax響應處理:

if (data.result == "success") { 
    window.location = data.redirect; 
} else { 
    $("#errorm").html(data.message); 
}