Please check the following code. It is very simple however, it
doesn't want to work as i would like it to. I checked the MySQL
database so that is not the problem. By the way, this code is not
all one page. I seperated the different files by comments.
<?php //Form page ?>
<HTML>
<HEAD>
<TITLE>TheADM</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
</HEAD>
<BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
<form name="form1" method="post">
<p>
<input name="f_user" type="text">
</p>
<p>
<input name="f_pass" type="password">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>
<?php
//Authenticate page
//What does status equal?
$status = authenticate($f_user, $f_pass);
//Begin the other page showing results
//Lets code the meat of the application
if ($status == 1)
{ //If user exists and pass is correct
//Start a session
session_start();
//Register some variables (We will use these on the pages)
session_register('SESSION');
//I want to display the username on the page, if the person is logged in
session_register('LoginName');
$LoginName = $f_user;
//Now we redirect people to the index, but as logged in
header("Location: ./index.php");
exit();
}
//Else if there is no user...
else
{
//Tell them nicely to go away
header("Location: /error.php?e=$status");
exit();
}
//I made 2 different authenticate functions but none work
function authenticate($user, $pass)
{
$username = '+++++';
$password = '+++++';
if ($user == $username && $pass == $password)
{
return 1;
}
else
{
return 0;
}
}
/* This part doesn't work either
//Returns 1 if valid combo, 0 if not
function authenticate($f_user, $f_pass)
{
//Configure variables we're going to use to access database
$db_user = '++++'; //Username used to login to MySQL
$db_pass = '++++'; //Password used with username
$db_name = '++++'; //The name of the database
$db_host = 'localhost'; //Host of the MySQL server
//OK. Now we're done setting those up, and now we can do the query variables
//Define our connection
$connection = mysql_connect($db_host, $db_user, $db_pass) or die ('Unable to connect to Server');
mysql_select_db($db_name); //Select the right database
//Store our query
$query = "SELECT id FROM passwords WHERE username = '$f_user' AND password = '$f_pass'";
//This is the return string
$result = mysql_query($query, $connection) or die ("Error in query: $query. " . mysql_error());
//Now we check our return string and see if the user exists or not
//If row exists, then user+pass combo is valid
if (mysql_num_rows($result) == 1)
{
//The user exists, so we return 1
return 1;
}
else
{
//The person doesn't exist in our database
return 0;
}
} */
?>
<?php
//Here's the error page
if ($e == 0)
{
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table width="792" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="159" height="123"> </td>
<td width="490" valign="top"><div align="center">
<p><font color="#FF0000" size="6">BAD LOGIN</font></p>
<p><font color="#FF0000" size="6">Your login info is incorrect<br>
Please try again</font></p>
</div></td>
<td width="143"> </td>
</tr>
<tr>
<td height="100"> </td>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>
<?php
}
else
{
echo("An unexpected error has occured!");
header("Location: ./index.php");
}
?>
So there it is. Any suggestions? Hints?
Thanks in advance