PHP代码是:
<?php
// Inialize session
session_start();
// Include database connection settings
include('config.inc');
// Retrieve username and password from database according to user's input
$sql ="SELECT * FROM user WHERE (email = '" . mysql_real_escape_string($_POST['username']) . "') and (password = '" . mysql_real_escape_string(md5($_POST['password'])) . "')";
$login = mysql_query($sql);
// Check username and password match
if (mysql_num_rows($login) == 1) {
// Set username session variable
$_SESSION['username'] = $_POST['username'];
// Jump to secured page
header('Location: http://localhost/site/client/index.php');
}
else {
// Jump to login page
header('Location: http://localhost/site/acces-client/index.php');
}
?>
这有效:
以下表单可以成功让用户登录并重定向:
<table border="0">
<form method="POST" action="loginproc.php">
<tr><td>Email:</td><td>:</td><td><input type="text" name="username" size="30"></td></tr>
<tr><td>Mot de passe:</td><td>:</td><td><input type="password" name="password" size="30"></td></tr>
<tr><td> </td><td> </td><td><input type="submit" value="Envoyer"></td></tr>
</form>
</table>
这不起作用: “不起作用”是指没有重定向。尽管调用了正确的 URL (http://localhost/site/client/index.php)。
$.post("http://localhost/site/loginproc.php", {username: email, password: motdepasse})
.success(function(result3){
});