Please see the below code which I have made for a simple user authentication system using sessions. I would be very greatful for any comments and suggestions to make it more secure or user friendly.
Login page (just the form part):
<form action="authenticate.php" method="post" name="authUser" enctype="multipart/form-data">
<table width=50% align="center">
<tr bgcolor="#FFFFFF" class="blacktext">
<td width="30%"><div align="right"><strong><font color="#350000" face="Verdana, Arial, Helvetica, sans-serif">Email:</font></strong></div></td>
<td width="70%" class="blacktext"><font color="#350000" face="Verdana, Arial, Helvetica, sans-serif">
<input type="text" size=25 name="username">
</font></td>
</tr>
<tr valign="top" bgcolor="#FFFFFF" class="blacktext">
<td width="30%" height="26"><div align="right"><strong><font color="#350000" face="Verdana, Arial, Helvetica, sans-serif">Password:</font></strong></div></td>
<td width="70%" class="blacktext"><font color="#350000" face="Verdana, Arial, Helvetica, sans-serif">
<input name="pwd" type="password" size="25">
</font></td>
</tr>
<tr valign="top" bgcolor="#FFFFFF" class="blacktext">
<td height="26" colspan="2" align="center">
<font color="#350000" face="Verdana, Arial, Helvetica, sans-serif">
<strong><input type="submit" value="Login"></strong>
</font></td>
</tr>
</table>
Authenticate.php
<?php
if (!$username || !$pwd) { print "ERROR - Missing user name or password."; exit; }
else {
include("mysql.inc");
$result = mysql_query( "SELECT * FROM loginTable WHERE email='$username' && password='$pwd'");
$num_rows = mysql_num_rows( $result );
if ($num_rows != "1") { print "ERROR - Your username and password do not match."; exit; }
else {
session_start();
session_register( "username" );
mysql_close( $link );
include("newpage.php"); }
}
?>
newpage.php
<?php include("validate.inc"); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
Welcome to the password protected page!!!!
<br><a href="nextpage.php">link to next page</a>
</body>
</html>
validate.inc
<?php
session_start();
// print session_encode();
if ( isset( $_SESSION[ 'username' ] ) && ( $_SESSION[ 'username' ] = $username ) )
{
}
else
{
include("emptyUser.php");
exit;
}
?>
nextpage.php
<?php include("validate.inc"); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
This is the second page of the site
</body>
</html>
I hope that all makes sense. It seems to work, but perhaps there there are some security issues I should be aware of?
Hopefully this will develop into an interesting discussion.
Rupert