Temper
12-30-2003, 06:34 PM
I want to create a login script for my webpage, but I'm having no luck at all. I'll give you what I have and I hope you can help me out.
The code on the Main index.php page:
<? session_start();
include("func_lst.php");
db_connect();
if(!isset($username) | !isset($password)) {
$member = 1; }
else if(isset($username) | isset($password)) { logged_in_chk(); }
?>
Further down the page where I want the form of the login looks like this:
<? if ($member = "1") { not_logged_in(); }
elseif ($member = "2") { logged_in_err(); }
elseif ($member = "3") { logged_in(); }?>
This is func_lst.php:
<? function not_logged_in()
{ ?>
<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>
<? }
function logged_in_chk() {
session_register("username");
session_register("password"); // register username and password as session variables.
$sql = mysql_query("SELECT pword FROM lad_user WHERE uname = '$username'");
$fetch_em = mysql_fetch_array($sql);
$numrows = mysql_num_rows($sql);
if($numrows != "0" & $password == $fetch_em["pword"]) {
$valid_user = 1;
$member = 3;
}
else {
$valid_user = 0;
$member = 2
}
if (!($valid_user))
{
session_unset(); // Unset session variables.
session_destroy(); // End Session we created earlier.
// escape from php mode.
} }
function logged_in_err() {
?>
<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>
<?
}
function logged_in() {
echo " You Are Logged in as: <Br>";
echo $username;
}
?>
The error I keep getting is it keeps displaying the "not_logged_in()" function, no matter what.
If you can, Please help me out.
Thank you
-Mike
The code on the Main index.php page:
<? session_start();
include("func_lst.php");
db_connect();
if(!isset($username) | !isset($password)) {
$member = 1; }
else if(isset($username) | isset($password)) { logged_in_chk(); }
?>
Further down the page where I want the form of the login looks like this:
<? if ($member = "1") { not_logged_in(); }
elseif ($member = "2") { logged_in_err(); }
elseif ($member = "3") { logged_in(); }?>
This is func_lst.php:
<? function not_logged_in()
{ ?>
<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>
<? }
function logged_in_chk() {
session_register("username");
session_register("password"); // register username and password as session variables.
$sql = mysql_query("SELECT pword FROM lad_user WHERE uname = '$username'");
$fetch_em = mysql_fetch_array($sql);
$numrows = mysql_num_rows($sql);
if($numrows != "0" & $password == $fetch_em["pword"]) {
$valid_user = 1;
$member = 3;
}
else {
$valid_user = 0;
$member = 2
}
if (!($valid_user))
{
session_unset(); // Unset session variables.
session_destroy(); // End Session we created earlier.
// escape from php mode.
} }
function logged_in_err() {
?>
<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>
<?
}
function logged_in() {
echo " You Are Logged in as: <Br>";
echo $username;
}
?>
The error I keep getting is it keeps displaying the "not_logged_in()" function, no matter what.
If you can, Please help me out.
Thank you
-Mike