<?php
$changesection='main';
$subtitle='Login';
if (isset($_POST['login']))
{
if ((!empty($_POST['username'])) && (!empty($_POST['password'])))
{
$users=mysql_query("select * from `users` where `username`='".quote_string($_POST['username'])."' limit 1",$db);
$user=mysql_fetch_assoc($users);
if (!empty($user))
{
$cryptedpassword=sha1($_POST['password']);
if ($cryptedpassword==$user['password'])
{
if (isset($_POST['savelogin']))
{
setcookie('id',$user['id'],time()+2592000);
setcookie('password',$cryptedpassword,time()+2592000);
}
$_SESSION['id']=$user['id'];
$_SESSION['userlevel']=$user['userlevel'];
mysql_query("update `sessions` set `userid`='".$user['id']."' where `sessionid`='".$sessionid."'",$db);
header('Location:'.$sessioncheckcaller.$sessionparm);
exit;
}
else
{
$changes[$changesection].='Invalid username/password';
}
}
else
{
$changes[$changesection].='Invalid username/password';
}
}
else
{
if (empty($_POST['username']))
{
$changes[$changesection].='No username<br>';
}
if (empty($_POST['password']))
{
$changes[$changesection].='No password<br>';
}
}
}
$changes[$changesection].='<form method="post" action="'.$sessioncheckcaller.'?subsite=login.php'.$sessionparm_link.'">';
$changes[$changesection].='<table class="vistable">';
$changes[$changesection].='<tr><td>Username:</td><td><input type="text" name="username"></td></tr>';
$changes[$changesection].='<tr><td>Password:</td><td><input type="password" name="password"></td></tr>';
$changes[$changesection].='</table>';
if ($session['cookies']==1)
{
$changes[$changesection].='Stay logged in:';
$changes[$changesection].='<input type="checkbox" name="savelogin"><br>';
}
$changes[$changesection].='<input type="submit" name="login" value="Login">';
$changes[$changesection].='</form>';
?>