Hello everyone,
I have a login script. It works perfectly fine however the session's seem to time out randomly and i don't know why. Has this ever happened to someone else? It seems to time out randomly. Here are the two files I have for the script....
FILE: secure.inc.php //USED AFTER access.inc.php FOR LOGGING IN
<?php
if(!loggedIn()):
?>
<form method="post" action="<?php echo $SERVER['PHP_SELF']; ?>">
<center>
<label>User Name:  <input type="text" value="" name="username" size="10"> </label>
<label>Password:  <input type="password" value="" name="pword" size="10"> </label>
<input type="submit" value="Login" size="9" style="font-family: Arial; font-size: 10pt">
</center>
</form>
<?php
else:
?>
<form method="post" action="<?php echo $SERVER['PHP_SELF']; ?>?logout=1">
<center>
<label><?php echo 'Welcome ' . $_SESSION['username'];?> <a class="MB" href="http://localhost/MegaByte/login/myaccount.php">My Account</a>  <input type="submit" value="logout"></label>
</center>
</form>
<?
endif;?>
AND
FILE access.inc.php //INCLUDED IN ALL THE SITE FILES.
<?php
session_start();
function loggedIn()
{
return isset($_SESSION['authorized']);
}
$dbcnx = @mysql_connect('localhost', 'root', '');
if(!$dbcnx)
{
exit('Error. Unable to connect to the server');
}
if(!@mysql_select_db('megabyte'))
{
exit('Error Unable to connect to the database');
}
if(isset($_POST['username']))
{
$user = $_POST['username'];
$sql = @("SELECT userName, pword, userPrivileges FROM users WHERE userName = '$user'");
if(!$sql)
{
exit('Error You Do Not Have An Account');
}
$userInfo = @mysql_fetch_array($sql);
$name = $userInfo['userName'];
$pword = $userInfo['pword'];
if($POST['pword'] == $pword && $POST['pword'] != "" && $POST['username'] != "")
{
$SESSION['authorized'] = TRUE;
$SESSION['username'] = $user;
$SESSION['userPrivileges'] = $userInfo['userPrivileges'];
}
}
if(isset($REQUEST['logout']))
{
unset($SESSION['authorized']);
}
?>
Thanks for any help.
Nick