EricTRocks
06-28-2007, 06:42 PM
I just need someone to check if this code is valid and secure. It works great so far. I don't have any errors. Let me know.
This is at the top of my index.php file:
<?php
session_start();
require "db_connect.php";
mysql_select_db("users");
if(isset($_POST['authenticate']))
{
// Variables
$xsidbuser = mysql_escape_string($_POST['xsidbuser']);
$xsidbpass = md5(mysql_escape_string($_POST['xsidbpass']));
// Query Database for User / Pass match
$auth_query = mysql_query("SELECT * FROM users WHERE uname='$xsidbuser' AND upass='$xsidbpass'");
$auth_count = mysql_num_rows($auth_query);
if($auth_count > 0)
{
session_start();
$_SESSION['logged_in'] = '1';
$_SESSION['xsidbuser'] = $xsidbuser;
unset($_SESSION['login_error']);
header ("Location: index.php");
exit();
}
else
{
$loginerror = "<p id='red'>Your login was invalid.</p>";
$_SESSION['logged_in'] = '0';
}
}
if(isset($_GET['logout']))
{
session_start();
session_unset();
session_destroy();
header ("Location: index.php");
exit();
}
?>
This is in an area for the login box:
<?php
if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] == '1')
{
// XSI DB User Variable
$xsidbuser = $_SESSION['xsidbuser'];
// Query for number of posted materials
$user_materials = mysql_num_rows(mysql_query("SELECT uname FROM users WHERE uname='$xsidbuser'"));
echo "<p id='logintext'><h1>Welcome: $xsidbuser</h1></p>\r\n<p>Posted Materials: $user_materials</p>\r\n\r\n<p><a href='" . $_SERVER['PHP_SELF'] . "?logout=1'>Logout</a> | View Profile</p>";
}
else
{
echo "$loginerror\r\n\r\n";
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data" method="post">
<fieldset>
<label for="xsidbuser">USER:</label>
<input name="xsidbuser" type="text" size="9" />
<label for="xsidbpass">PASS:</label>
<input name="xsidbpass" type="password" size="9" />
<input type="hidden" name="authenticate" />
<label for="authenticate"><!-- --></label>
<input id="loginbutton" type="image" src="images/button_login.gif" name="submit" />
<p><a href='#'>Register Now!</a></p>
</fieldset>
</form>
<?php
}
?>
Any and all help is appreciated!
Thanks,
Eric T.
This is at the top of my index.php file:
<?php
session_start();
require "db_connect.php";
mysql_select_db("users");
if(isset($_POST['authenticate']))
{
// Variables
$xsidbuser = mysql_escape_string($_POST['xsidbuser']);
$xsidbpass = md5(mysql_escape_string($_POST['xsidbpass']));
// Query Database for User / Pass match
$auth_query = mysql_query("SELECT * FROM users WHERE uname='$xsidbuser' AND upass='$xsidbpass'");
$auth_count = mysql_num_rows($auth_query);
if($auth_count > 0)
{
session_start();
$_SESSION['logged_in'] = '1';
$_SESSION['xsidbuser'] = $xsidbuser;
unset($_SESSION['login_error']);
header ("Location: index.php");
exit();
}
else
{
$loginerror = "<p id='red'>Your login was invalid.</p>";
$_SESSION['logged_in'] = '0';
}
}
if(isset($_GET['logout']))
{
session_start();
session_unset();
session_destroy();
header ("Location: index.php");
exit();
}
?>
This is in an area for the login box:
<?php
if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] == '1')
{
// XSI DB User Variable
$xsidbuser = $_SESSION['xsidbuser'];
// Query for number of posted materials
$user_materials = mysql_num_rows(mysql_query("SELECT uname FROM users WHERE uname='$xsidbuser'"));
echo "<p id='logintext'><h1>Welcome: $xsidbuser</h1></p>\r\n<p>Posted Materials: $user_materials</p>\r\n\r\n<p><a href='" . $_SERVER['PHP_SELF'] . "?logout=1'>Logout</a> | View Profile</p>";
}
else
{
echo "$loginerror\r\n\r\n";
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data" method="post">
<fieldset>
<label for="xsidbuser">USER:</label>
<input name="xsidbuser" type="text" size="9" />
<label for="xsidbpass">PASS:</label>
<input name="xsidbpass" type="password" size="9" />
<input type="hidden" name="authenticate" />
<label for="authenticate"><!-- --></label>
<input id="loginbutton" type="image" src="images/button_login.gif" name="submit" />
<p><a href='#'>Register Now!</a></p>
</fieldset>
</form>
<?php
}
?>
Any and all help is appreciated!
Thanks,
Eric T.