I know everyone likes using the password protect extension but that is not very secure. This PHP code can be used to secure your page.
There are two ways you can do it. Make sure that on both of them, you set each of the page extensions to PHP!
If you want to protect more than 1 page and you don't want the user to keep entering the password, use this way.
Insert this code in the pages you want protected.
Enter it in the Start of Page area.
Code: Select all
<?php
$password = "enter your password here...";
$bad_page = "enter the page that the user will be redirected to if it is a bad login.";
if($_GET["cmd"] == "verify")
{
if(!($_GET["password"] == $password))
{
header('Location: '.$bad_page);
}
else
{
session_start();
$_SESSION["loggedin"]="true";
}
}
?>
Code: Select all
<?php
// EDIT THIS BIT AT YOUR OWN RISK
if($_SESSION["loggedin"] == "true")
{
?>
Code: Select all
<?php
// EDIT THIS BIT AT YOUR OWN RISK
}
if(!($_SESSION["loggedin"] == "true"))
{
// Edits allowed
?>
<font face="arial" size="2">A password is required to access this page.<br>
Please enter the password below.<br>
<form action="<?php echo $_SERVER['PHP_SELF']?>">
<input type=hidden name=cmd value=verify>
<input type=password name=password>
<input type=submit value=Enter></form>
<?php
}
?>
use this code.
Insert this code in the start of your page:
Code: Select all
<?php
$password = "your password...";
$bad_page = "incorrect password page...';
if($_GET["cmd"] == "verify")
{
if(!($_GET["password"] == $password)
{
header('Location: '.$bad_page)
}
}
?>
Code: Select all
<?php
if($_GET["password"] == $password)
{
?>
Code: Select all
<?php
// EDIT THIS BIT AT YOUR OWN RISK
}
if(!($_SESSION["loggedin"] == "true"))
{
// Edits allowed
?>
<font face="arial" size="2">A password is required to access this page.<br>
Please enter the password below.<br>
<form action="<?php echo $_SERVER['PHP_SELF']?>">
<input type=hidden name=cmd value=verify>
<input type=password name=password>
<input type=submit value=Enter></form>
<?php
}
?>
