Quote:
Originally Posted by calmlikeabomb
PHP Code:
<?
ob_start();
if(isset($_POST['login'])) {
if($_POST['username'] == 'admin' && $_POST['password'] == 'admin') {
setcookie("TestCookie", $_POST['username']);
header("Location: /admin/"); ob_flush(); exit();
}
print <<<LoginForm
<form action=$_SERVER[PHP_SELF]" method="POST">
<input type="text" name="username" />
<input type="password" name="password" />
<input type="submit" name="login" value="Login"/>
</form>
LoginForm;
?>
Then on the pages you need to protect
PHP Code:
if(!isset($_COOKIE['TestCookie'])) { header("Location: /login/"); ob_flush(); exit(); }
|
It is not best way. if you want to use a COOKIE
use it with SESSIONS. Many peple have turn off cookies.
Script that fill the session from login form
PHP Code:
<?php
session_start();
$_SESSION['Test'] = true;
$_SESSION['UserName'] = addslashes($_POST['UserName']);
$_SESSION['Password'] = md5(addslashes($_POST['UserName']));
?>
Page that you need protect
PHP Code:
<?php
session_start();
if (!isset($_SESSION['Test']))
{
// redirect back on login script
}
?>
You can save into SESSION what you want and chacked it with database or other resources that you have store in another place.