Authorize view by IP (Simple Script)
This is like THE simplest, easiest way to make a certain web page only viewable by certain IP[s].
<?php
/*****************************
* Fetch IP
* You can also use:
* $ip = $_SERVER["REMOTE_ADDR"];
* Instead of:
* $ip = getnv(”REMOTE_ADDR”);
******************************/$ip = getenv(”REMOTE_ADDR”);
// Add authorised IPs here
// example: $myip[0] = “127.0.0.1″;$myip[0] = “IP_HERE”;
$myip[1] = “IP_HERE”;/************************************************
* If you want to add more IPs, just copy the $myip line
* and change the IP and [0] accordingly
* [0] = first IP, [1] = second, [2] = thrid, and so on.
*
* Also if you are going to add another IP, don’t forget to
* edit the if line, for example, if you added a third IP
*
* this:
* if ($ip == $myip[0] || $ip == $myip[1])
*
* should be:
* if ($ip == $myip[0] || $ip == $myip[1] || $ip == $myip[2])
**************************************************/if ($ip == $myip[0] || $ip == $myip[1]) {
?>Your Site Content
<?php
}
else {
echo “Your IP is not authorized to view this page”;
}
?>
Of course there are many other ways in doing this, like using array(”ip1″, “ip2″), but this is the easiest one to understand for people who don’t know much about PHP.
This can basically be used for paranoid security, htpasswd + that script will make your page very secure.
Enjoy.
Article by el_jentel1

August 10th, 2008 at 11:21 pm
That scripts easy to bypass. It would block newbies, but not people with experience.
August 11th, 2008 at 10:27 am
Why don’t you use in_array in the if?
August 11th, 2008 at 1:14 pm
If you read my comment after the script, you’d see that its not the “only” way, its the simplest way for people that don’t know much about PHP, if you want to comment with a better one, by all means go ahead, I’m sure some will be interested in a “Simple” and an “Advanced” version.
August 13th, 2008 at 10:25 am
Seria mais facil usar o array com foreach :/
August 13th, 2008 at 12:49 pm
Anglish please.
October 28th, 2008 at 6:24 am
October 28th, 2008 at 6:25 am
Code not showing up ^ - here it is again.
$allowedips = array(’127.0.0.1′, ‘192.168.1.1′);
if (!in_array($_SERVER['REMOTE_ADDR'], $allowedips)) die(’Access Denied’);
November 22nd, 2008 at 11:48 am
Good site I “Stumbledupon” it today and gave it a stumble for you.. looking forward to seeing what else you have..later
December 30th, 2008 at 3:57 am
Amoxicillin dosage….
Amoxicillin for acne. Amoxicillin price. Amoxicillin alternative. Amoxicillin dosage for greyhound sinus infection….