<?php
$logins = (isset($_COOKIE['passwordPages'])) ? explode("@#@", $_COOKIE['passwordPages']) : array();
$password = $mysql->get_array($mysql->query("password,password_msg", $mysql->perfix."pages", "ID = {$url['pid']} $pubSQL LIMIT 1"));
//check login
$error = '';
if(isset($_POST['passProtectPagespassword']))
{
if($_POST['passProtectPagespassword'] != $password['password'])
{
$error = '<p style="font-weight:bold;" align="center">Sorry, please enter the correct password.</p>';
}
else
{
$val = implode("@#@", $logins).'@#@'.md5($password['password']);
setcookie('passwordPages', $val, 0, '/');
header("Location: ".current_page());
exit;
}
}
//
if($password['password'] != '' && !in_array(md5($password['password']), $logins))
{
$temp = explode("<!--tc-->", $mainhtml);
$mainhtml = $temp[0].'<h1>Password required</h1>';
$mainhtml .= (empty($password['password_msg'])) ? '<p>Sorry, this page is password protected. Please enter the password below to view it.</p>' : '<p>'.stripslashes(nl2br($password['password_msg'])).'</p>';
$mainhtml .= $error.'<p><form action="" method="post"><input name="passProtectPagespassword" id="passProtectPagespassword" type="password" size="32" /> <input type="submit" id="s" name="s" value="Login" /></form></p>';
$mainhtml .= $temp[2];
}
?>