PHP code is:
<?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');
}
?>
This works:
The following form can successfully get the user logged and redirected:
<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>
This does not work: by "does not work", I mean there is no redirect. Although the correct URL is called (http://localhost/site/client/index.php).
$.post("http://localhost/site/loginproc.php", {username: email, password: motdepasse})
.success(function(result3){
});