Posts Tagged ‘easy’
Simple PHP Page Protector
A couple of years ago I posted a way to protect a PHP page from access on the internet in an easy way.
I've spent around 15 minutes producing what I feel is a better version of the same script at the original post.
In order for it to work, you'll need a MD5 string, which you can get using the below box, just enter you password and then replace 6121904d3138741fb744fba85c276606 in the code, its quite self-explanatory.
session_start();
$_userpassword = "6121904d3138741fb744fba85c276606";
$_username = "pass";
/*DO NOT EDIT*/
if ($_POST['pageprotector'])
{
if (md5($_POST['pageprotectorpass']) == $_userpassword && $_POST['pageprotectoruser'] == $_username)
{
$_SESSION['bG9nZ2VkaW4p=']=$_userpassword; $_SESSION['bG9nZ2VkaW4u=']=$_username; header('Location:'.$_SERVER['PHP_SELF']);
}
else
header('Location:'.$_SERVER['PHP_SELF'].'?wrongpass=1');
}
if ($_GET['pageprotectlogout'] == "1")
{
unset($_SESSION['bG9nZ2VkaW4p=']);unset($_SESSION['bG9nZ2VkaW4u=']);header('Location:'.$_SERVER['PHP_SELF']);
}
if ($_SESSION['bG9nZ2VkaW4p='] != $_userpassword && $_SESSION['bG9nZ2VkaW4u='] != $_username)
{
if ($_GET['wrongpass'] == "1") echo "Wrong password";?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Username: <input name="pageprotectoruser" type="text" /> Password: <input name="pageprotectorpass" type="text" /><input name="pageprotector" type="submit" value="Login">
</form><?php
exit;
}
/*DO NOT EDIT ABOVE*/
?>
Data Types in PHP
PHP is not a very strict language when it comes down to data types.
Strings:
Strings are values that contain characters. This can include basically everything you can type on your keyboard.
Integers:
Integers are values that just contain numbers. Notice in the example above that there are no quotes?
Well, you can write an integer like that, or like this:
PHP automatically converts numbers contained in a string with no other characters into a integer. The only time you need to be careful of this is when you are using operators (I will discuss that in another post).
Boolean:
$string2 = false;
Booleans are values that contain either true or false. They can be used in if statements like:
if ($string)//checks if $string is true
{
echo '$string is true';
}
else
{
echo '$string is false';
}
Hope that helps you understand data types in PHP better. Obviously I have just scratched the surface in my explanations.
Feel free to comment and ask any questions ![]()
![]()
