I seem to still be having intermittent problems with this auto login.
Here is the login.php
To see what happens...
www.trackerplus.net click on the Demo
Thanks
Peer
<?php
ini_set("display_errors","1");
ini_set("display_startup_errors","1");
session_start();
if(!@$_SESSION["MyURL"])
session_unset();
set_magic_quotes_runtime(0);
include("include/dbcommon.php");
include("include/dbconnection.php");
$myurl=@$_SESSION["MyURL"];
unset($_SESSION["MyURL"]);
$cLoginMethod = 1;
$cUserName = "";
$cPassword = "";
$cAdminUserID = "admin";
$strMessage="";
if (@$_REQUEST["lang"])
{
$_SESSION["language"]=@$_REQUEST["lang"];
}
if (@$_REQUEST["btnSubmit"] == "Login")
{
if(@$_REQUEST["remember_password"] == 1)
{
setcookie("username",@$_REQUEST["username"],time()+365144060);
setcookie("password",@$_REQUEST["password"],time()+365144060);
$strChecked = " checked";
}
else
{
setcookie("username","",time()-365144060);
setcookie("password","",time()-365144060);
$strChecked = "";
}
if($cLoginMethod == LOGIN_HARDCODED)
{
// username and password are hardcoded
if(!strcmp($cPassword, @$_REQUEST["password"]) && !strcmp($cUserName, @$_REQUEST["username"]))
{
$_SESSION["UserID"] = $_REQUEST["username"];
$_SESSION["AccessLevel"] = ACCESS_LEVEL_USER;
if($myurl)
header("Location: ".$myurl);
else
header("Location: ".str_replace(" ","%20","menu.php"));
return;
}
else
{
$strMessage = "Invalid Login";
session_unset();
}
}
else
{
// username and password are stored in the database
$conn=db_connect();
$strUsername = (string)@$_REQUEST["username"];
$strPassword = (string)@$_REQUEST["password"];
$rstemp=db_query("select from ".AddTableWrappers($cLoginTable)." where 1=0",$conn);
if(NeedQuotes(db_fieldtype($rstemp,$cUserNameField)))
$strUsername="'".db_addslashes($strUsername)."'";
else
$strUsername=(0+$strUsername);
if(NeedQuotes(db_fieldtype($rstemp,$cPasswordField)))
$strPassword="'".db_addslashes($strPassword)."'";
else
$strPassword=(0+$strPassword);
$strSQL = "select from ".AddTableWrappers($cLoginTable)." where ".AddFieldWrappers($cUserNameField).
"=".$strUsername." and ".AddFieldWrappers($cPasswordField).
"=".$strPassword;
$rs=db_query($strSQL,$conn);
if($data=db_fetch_array($rs))
{
$_SESSION["UserID"] = @$_REQUEST["username"];
$_SESSION["AccessLevel"] = ACCESS_LEVEL_USER;
if($_REQUEST["username"]==$cAdminUserID)
$_SESSION["AccessLevel"] = ACCESS_LEVEL_ADMIN;
if(strlen("user_id"))
$_SESSION["OwnerID"] = $data["user_id"];
if($myurl)
header("Location: ".$myurl);
else
header("Location: ".str_replace(" ","%20","menu.php"));
return;
}
else
{
$strMessage = "Invalid Login";
session_unset();
}
}
}
else
$strChecked = " checked";
if($myurl)
$_SESSION["MyURL"]=$myurl;
if(@$_REQUEST["username"])
$strUsername = $_REQUEST["username"];
else
$strUsername = @$_COOKIE["username"];
if(@$_REQUEST["password"])
$strPassword = $_REQUEST["password"];
else
{
$strPassword = @$_COOKIE["password"];
$strPassword = "";
}
if(@$_GET["message"]=="expired")
$strMessage = "Your session has expired. Please login again.";
?>
<html>
<head>
<title>Login</title>
<link REL="stylesheet" href="include/style.css" type="text/css">
</head>
<script language = JavaScript>
function OnKeyDown()
{
e = window.event;
if (e.keyCode == 13)
{
e.cancel = true;
document.forms[0].submit();
}
}
</script>
<body bgcolor=white onLoad="java script:document.forms[0].username.focus();document.forms[0].password.onkeydown = OnKeyDown;" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" link="#0066cc">
<?php
if(file_exists("include/supertop.php"))
include("include/supertop.php");
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="99%">
<tr>
<td valign="center" align="middle">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#ffffff" valign="top" align="right">
<table width="300" border="0" cellspacing="4" cellpadding="4" align="center">
<tr>
<td> </td>
</tr>
</table>
<form method="POST" action="login.php" id=form1 name=form1>
<table width="300" border="0" cellspacing="1" cellpadding="4" align="center" bgcolor="#cccccc">
<tr>
<td align=middle class=blackshade>
<b><font size=+1>Login</font></b></td>
</tr>
<tr>
<td valign="top" class=shade>
<DIV align=center>
<table width="200" border=0 align="center" class=shade>
<tbody>
<tr height=10><td colspan=2> </td></tr>
<tr>
<td align=right width="50%">
<div align="left">Username:</div>
</td>
<td width="50%">
<input name=username value="<?php echo htmlspecialchars($strUsername);?>">
</td>
</tr>
<tr>
<td align=right width="50%">
<div align="left">Password:</div>
</td>
<td width="50%">
<input type=password name=password value="<?php echo htmlspecialchars($strPassword);?>">
</td>
</tr>
<tr>
<td align=right width="50%">
<div align="left">Remember Password::</div>
</td>
<td width="50%">
<input type=checkbox name=remember_password value="1" <?php echo $strChecked;?>>
</td>
</tr>
<tr>
<td colspan=2 align=middle>
<input type=hidden name=btnSubmit value="Login">
<input type=submit value="Submit" class=buttonM>
</td>
</tr>
<tr>
<td colspan=2 align=middle>
<a href="register.php">Register</a>
<a href="remind.php">Forgot password?</a>
</td>
</tr>
<tr height=20>
<td align=center colspan=2>
<font color=red><?php echo $strMessage;?></font>
</td></tr>
</tbody>
</table></DIV>
</td>
</tr>
</table>
</form>
<p> </p></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?php
if(file_exists("include/superbottom.php"))
include("include/superbottom.php");
?>
</body>
</html>
<?php
?>