Reputation: 47
I am using something similar to the following code to log a user in and redirect that user to a new web page once they are logged in:
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="css/style.css" />
<title>application</title>
</head>
<body bgcolor="#FFFFCC">
<div id="LoginPage">
<form method="GET" action="validateLogin.php">
<table style="font-size: 12px; line-height: 0;">
<tr>
<td align="right" bgcolor="#3333FF"><p id="text">Trader Id:</p></td>
<td align="left" bgcolor="#3333FF">
<input type="text" name="user">
</td>
</tr>
<tr>
<td align="right" bgcolor="#3333FF"><p id="text">Password:</p></td>
<td align="left" bgcolor="#3333FF"><input type="password" name="pass"></td>
</tr>
<tr>
<td>
<input type="hidden" size="50" value="<?php echo $var; ?>"/>
</td>
</tr>
<tr>
<td align="right" bgcolor="#FFFFCC"><p id="text"></p></td>
<td align="right" bgcolor="#FFFFCC"><p id="text"></p></td>
</tr>
<tr>
<td align="right" bgcolor="#FFFFCC"><p id="text"></p></td>
<td align="center" bgcolor="#B3B3B3"><input type="submit" value="Login"></td>
</tr>
</table>
</form>
</div>
</body>
</html>
EDITED
PHP
$query = mysql_query("SELECT username FROM Users WHERE username=$username");
if (mysql_num_rows($query) != 0) {
echo 1;
} else {
echo -1;
}
My PHP validation script (validateLogin.php) returns 1 if the user is logged in and -1 if they do not have an account. How can I modify this script so that when the user logs in, and logs in successfully, they are redirected to a new page rather than being shown the -1 or 1 return?
Upvotes: 1
Views: 157
Reputation: 10121
Just add this into your condition
if (mysql_num_rows($query) != 0) {
header('Location:success.php');
} else {
header('Location:login.php');
}
Upvotes: 0
Reputation: 7769
$query = mysql_query("SELECT username FROM Users WHERE username=$username");
if (mysql_num_rows($query) == 1){
header('Location:success.php'); //Login successfull
}else{
header('Location:login.php'); //Login failed
}
Upvotes: 3