Posts Tagged ‘simple’
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*/
?>
A Simple Banner Rotator Script
I'm in the coding mood today
.
I cannot count how many times I've been asked to code a UBER simple banner rotator script.
These things are so simple, but if you don't know PHP it can be difficult to understand.
The script below has two variables:
"http://www.google.com",
"http://www.msn.com",
"http://forums.digitalpoint.com"
);
//add a new link for the banner to a new line in the same format as above
and:
"http://www.google.co.uk/intl/en_uk/images/logo.gif",
"http://stc.msn.com/br/hp/en-us/css/35/decoration/msn_b.gif",
"http://forums.digitalpoint.com/images/misc/dps_logo.gif"
);
//add a new image link for the banner to a new line in the same format as above
As you can see they match up. The first line for the $links variable is for a google image, the second is for a msn image etc.
Here is the full code:
session_start();
$links = array(
"http://www.google.com",
"http://www.msn.com",
"http://forums.digitalpoint.com"
);
//add a new link for the banner to a new line in the same format as above
$images = array(
"http://www.google.co.uk/intl/en_uk/images/logo.gif",
"http://stc.msn.com/br/hp/en-us/css/35/decoration/msn_b.gif",
"http://forums.digitalpoint.com/images/misc/dps_logo.gif"
);
//add a new image link for the banner to a new line in the same format as above
//-------- DO NOT EDIT BELOW THIS LINE----------
$count = count($links) -1;
$randnum = mt_rand(0,$count);
if ($randnum == $_SESSION['randnum'])
{
$randnum = mt_rand(0,$count);
}
$_SESSION['randnum'] = $randnum;
echo '<a href="'.$links[$randnum].'"><img style="border:none" src="'.$images[$randnum].'" /></a>';
?>
The code has been constructed so that the likelihood of getting the same banner displayed twice is greatly reduced.
Comment here if you like the script, or have any questions
You can see an example of the script running here.
![]()
