Interesting ... Try now
PHP Code:
<?
function login_form() {?>
<form method="post" action="<? Echo($_SERVER['PHP_SELF']);?>">
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<input type="hidden" name="login" value="true" />
<input type="submit" name="login" value=" Login " /> <input type="reset" value=" Reset " />
</form>
<? }
If($_POST['login']) {
$username=mysql_real_escape_string($_POST['username']);
$password=mysql_real_escape_string($_POST['password']);
$query=mysql_query("SELECT * FROM users WHERE username='".$username."' AND password='".$password."' LIMIT 1");
If(mysql_num_rows($query) > 0) {
setcookie("loggedin","true",time+36000); //1 day
sleep(1);
}
mysql_free_result($query);
header("Location: ".$_SERVER['PHP_SELF']);
exit;
}
If($_COOKIE['loggedin']!="true") {
Echo(" You do not have permission to access this page. Please login Below. ");
login_form(); // print the login form
exit;
}?>