Forums

PHP

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>
&lt;?
$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
?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;login&lt;/title&gt;
&lt;head&gt;
&lt;body&gt;
&lt;form action="&lt;?=$php_SELF?&gt;&lt;?if($QUERY_STRING){ echo"?". $QUERY_STRING;}?&gt;" method="POST"&gt;
&lt;p align="center"&gt;Members only. Please login to access this document.&lt;/p&gt;
&lt;table align="center" border="0"&gt;
&lt;tr&gt;
&lt;th&gt;
Username:
&lt;/th&gt;
&lt;th&gt;
&lt;input type="text" name="username"&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;
Password:
&lt;/th&gt;
&lt;th&gt;
&lt;input type="password" name="password"&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th colspan="2" align="right"&gt;
&lt;input type="submit" value="login"&gt;
&lt;/form&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;?
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.
?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;login&lt;/title&gt;
&lt;head&gt;
&lt;body&gt;
&lt;form action="&lt;?=$php_SELF?&gt;&lt;?if($QUERY_STRING){ echo"?". $QUERY_STRING;}?&gt;" method="POST"&gt;
&lt;p align="center"&gt;Incorrect login information, please try again. You must login to access this document.&lt;/p&gt;
&lt;table align="center" border="0"&gt;
&lt;tr&gt;
&lt;th&gt;
Username:
&lt;/th&gt;
&lt;th&gt;
&lt;input type="text" name="username"&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;
Password:
&lt;/th&gt;
&lt;th&gt;
&lt;input type="password" name="password"&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th colspan="2" align="right"&gt;
&lt;input type="submit" value="login"&gt;
&lt;/form&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;?
exit();
}
?&gt; </font id=code></pre id=code>

Hope this helps

Edited by - logizone on 15 Aug 2003 21:14:49

Reply to this topic