Forums
This topic is locked
Login & redirect
Posted 10 Aug 2003 22:05:50
1
has voted
10 Aug 2003 22:05:50 D.D.M. van Zelst posted:
Does anyone know a php/mySQL script or extension which enables me to create a login page and let users who login redirect to their personal page depending on their username and password?? I only can find login scripts that redirects to one page based on succesfull login.Thnx.
Edited by - davaze on 10 Aug 2003 22:07:19
Replies
Replied 15 Aug 2003 21:14:04
15 Aug 2003 21:14:04 Mike McGuire replied:
Try something like this:
<pre id=code><font face=courier size=2 id=code>
<?
$dbh=mysql_connect ("localhost", "bloomers", "******" or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("bloomers_portal"
if(!isset($username) ¦¦!isset($password)) {
// escape from php mode and show login page
?>
<html>
<head>
<title>login</title>
<head>
<body>
<form action="<?=$php_SELF?><?if($QUERY_STRING){ echo"?". $QUERY_STRING;}?>" method="POST">
<p align="center">Members only. Please login to access this document.</p>
<table align="center" border="0">
<tr>
<th>
Username:
</th>
<th>
<input type="text" name="username">
</th>
</tr>
<tr>
<th>
Password:
</th>
<th>
<input type="password" name="password">
</th>
</tr>
<tr>
<th colspan="2" align="right">
<input type="submit" value="login">
</form>
</th>
</tr>
</table>
</body>
</html>
<?
exit();
}
// If all is well so far.
// Here you would check the supplied username and password against your database to see if they exist.
// For example, a MySQL Query, your method may differ.
$sql = mysql_query("SELECT password,redirect FROM user_table WHERE username = '$username'"
$fetch_em = mysql_fetch_array($sql);
$numrows = mysql_num_rows($sql);
if($numrows!= "0" & $password == $fetch_em["password"]) {
// correct login
$valid_user = 1;
header("Location: ".$fetch_em["redirect"]);
exit;
}
else {
$valid_user = 0;
}
// If the username exists and pass is correct, don't pop up the login code again.
// If info can't be found or verified....
if (!($valid_user))
{
// escape from php mode and show login error page.
?>
<html>
<head>
<title>login</title>
<head>
<body>
<form action="<?=$php_SELF?><?if($QUERY_STRING){ echo"?". $QUERY_STRING;}?>" method="POST">
<p align="center">Incorrect login information, please try again. You must login to access this document.</p>
<table align="center" border="0">
<tr>
<th>
Username:
</th>
<th>
<input type="text" name="username">
</th>
</tr>
<tr>
<th>
Password:
</th>
<th>
<input type="password" name="password">
</th>
</tr>
<tr>
<th colspan="2" align="right">
<input type="submit" value="login">
</form>
</th>
</tr>
</table>
</body>
</html>
<?
exit();
}
?> </font id=code></pre id=code>
Hope this helps
Edited by - logizone on 15 Aug 2003 21:14:49
<pre id=code><font face=courier size=2 id=code>
<?
$dbh=mysql_connect ("localhost", "bloomers", "******" or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("bloomers_portal"
if(!isset($username) ¦¦!isset($password)) {
// escape from php mode and show login page
?>
<html>
<head>
<title>login</title>
<head>
<body>
<form action="<?=$php_SELF?><?if($QUERY_STRING){ echo"?". $QUERY_STRING;}?>" method="POST">
<p align="center">Members only. Please login to access this document.</p>
<table align="center" border="0">
<tr>
<th>
Username:
</th>
<th>
<input type="text" name="username">
</th>
</tr>
<tr>
<th>
Password:
</th>
<th>
<input type="password" name="password">
</th>
</tr>
<tr>
<th colspan="2" align="right">
<input type="submit" value="login">
</form>
</th>
</tr>
</table>
</body>
</html>
<?
exit();
}
// If all is well so far.
// Here you would check the supplied username and password against your database to see if they exist.
// For example, a MySQL Query, your method may differ.
$sql = mysql_query("SELECT password,redirect FROM user_table WHERE username = '$username'"
$fetch_em = mysql_fetch_array($sql);
$numrows = mysql_num_rows($sql);
if($numrows!= "0" & $password == $fetch_em["password"]) {
// correct login
$valid_user = 1;
header("Location: ".$fetch_em["redirect"]);
exit;
}
else {
$valid_user = 0;
}
// If the username exists and pass is correct, don't pop up the login code again.
// If info can't be found or verified....
if (!($valid_user))
{
// escape from php mode and show login error page.
?>
<html>
<head>
<title>login</title>
<head>
<body>
<form action="<?=$php_SELF?><?if($QUERY_STRING){ echo"?". $QUERY_STRING;}?>" method="POST">
<p align="center">Incorrect login information, please try again. You must login to access this document.</p>
<table align="center" border="0">
<tr>
<th>
Username:
</th>
<th>
<input type="text" name="username">
</th>
</tr>
<tr>
<th>
Password:
</th>
<th>
<input type="password" name="password">
</th>
</tr>
<tr>
<th colspan="2" align="right">
<input type="submit" value="login">
</form>
</th>
</tr>
</table>
</body>
</html>
<?
exit();
}
?> </font id=code></pre id=code>
Hope this helps
Edited by - logizone on 15 Aug 2003 21:14:49