Hello,
I am trying to password protect a website that i am making, and have successfully done so using Zubrags password protect script. I want to slightly modify the script so that depending on what password a user enters, a different version of the site will be displayed. My knowledge of PHP (unfortunately) is fairly limited, i can decipher code and write a little, but cannot work out how to successfully implement what i want to achieve.
I have modified the script thus far and have now run in to a problem with the cookies, in that i dont think the cookie is being set properly.
Due to my lack of PHP I also cannot work out how to implement the feature of entering a different password will lead you to a different version of the site....
Here is the code:
With regards to adding the different version of the site, i believe i need to add some if statements such as the following:PHP Code:<?php
##################################################################
# SETTINGS START
##################################################################
$LOGIN_INFORMATION = array(
'default'
);
define('TIMEOUT_MINUTES', 15);
define('TIMEOUT_CHECK_ACTIVITY', true);
##################################################################
# SETTINGS END
##################################################################
// timeout in seconds
$timeout = (TIMEOUT_MINUTES == 0 ? 0 : time() + TIMEOUT_MINUTES * 60);
if(!function_exists('showLoginPasswordProtect')) {
// show login form
function showLoginPasswordProtect($error_msg) {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "(URL address blocked: See forum rules)">
<html xmlns="(URL address blocked: See forum rules)">
<head>
<meta http-equiv="CACHE-CONTROL" content="NO-CACHE">
<meta http-equiv="PRAGMA" content="NO-CACHE">
<meta name="robots" content="noindex" />
<title>Please Login</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="fonts.css" rel="stylesheet" type="text/css" />
<link href="scripts/style.css" rel="stylesheet" type="text/css" />
<link href="scripts/fonts.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="errorholder">
<h1>Please enter the password <br/> to access this site</h1><br/>
<form name="form" method="post">
<p class="bluetext"><?php echo $error_msg; ?> </p>
<input type="password" title="password" name="access_password" /></p><br/>
<p><input type="submit" name="submit" value="Valider" /></p>
</form>
</div>
</body>
</html>
<?php
// stop at this point
die();
}
}
// user provided password
if (isset($_POST['access_password'])) {
$pass = $_POST['access_password'];
if (!in_array($pass, $LOGIN_INFORMATION)
)
{
showLoginPasswordProtect("Incorrect Password");
}
else {
// set cookie if password was validated
setcookie("verify", md5($pass), $timeout, '/');
unset($_POST['access_password']);
unset($_POST['Submit']);
}
}
else {
// check if password cookie is set
if (!isset($_COOKIE['verify'])) {
showLoginPasswordProtect("");
}
// check if cookie is good
$found = false;
if ($_COOKIE['verify'] == md5($pass)) {
$found = true;
// prolong timeout
if (TIMEOUT_CHECK_ACTIVITY) {
setcookie("verify", md5($pass), $timeout, '/');
}
break;
}
}
if (!$found) {
showLoginPasswordProtect("");
}
?>
I am extremely lost and confused and my severe lack of PHP knowledge has got me stuck. I know its a big ask, but if anyone can help or point me in the right direction i would be ever so grateful!PHP Code:if (($_POST == $LOGIN_INFORMATION1 ))
{
Header("Location:pagename01.php");
exit();
}
if($_POST == $LOGIN_INFORMATION2)
{
Header("Location:pagename02.php");
exit();
}
Kind regards
Matt


Reply With Quote
Bookmarks