non data base
<?php
//set password for this page
$p = "zjUG8FhIAFHf";
$pass = $_POST['pass']==$p?TRUE:FALSE;
if(!$pass)
{?>
<form method="POST">
Pass <input type="password" name="pass"></input><br/>
<input type="submit" name="submit" value="Go"></input>
</form>
<?
die();
}
?>
มี data base
<?php
$canPass = FALSE;
//get current password
if($_SESSION['user_id']){
$conn = db_open_connection();
$sql = "SELECT `pass` FROM `allpassword` where `user_id`='$_SESSION['user_id']'";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
//set password for this page
$p = $row["pass"];
$canPass= $_POST['pass']==$p?TRUE:FALSE;
db_close_connection($conn);
}
if(!$canPass)
{?>
<form method="POST">
Pass <input type="password" name="pass"></input><br/>
<input type="submit" name="submit" value="Go"></input>
</form>
<?
die();
}
?>