Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // hand coded blacklisted ips.
- $denied_ips = array(
- '123.456.789.1',
- '127.0.0.1',
- '67.220.200.75',
- '60.13.126.151',
- '77.20.163.164',
- '94.74.136.69',
- '94.195.205.180',
- '64.30.102.114',
- '85.17.145.48',
- '91.214.44.229',
- '92.240.68.152',
- '61.160.216.63',
- '213.194.173.90',
- '210.196.130.73',
- '60.13.126.151',
- '89.122.29.80',
- '88.80.7.248',
- '89.149.253.58',
- '140.239.67.40',
- '67.205.89.102',
- '60.251.220.61',
- '58.246.73.74',
- '67.201.56.122',
- '188.92.75.23',
- '203.152.210.122',
- '211.153.32.123',
- '88.203.203.150',
- '85.12.43.203',
- '92.68.249.36',
- '193.224.106.188'
- );
- // Or use a file for the blacklisted ips.
- // $denied_ips = file(‘ips.txt’);
- function getUserIP()
- {
- $alt_ip = $_SERVER['REMOTE_ADDR'];
- if (isset($_SERVER['HTTP_CLIENT_IP']))
- {
- $alt_ip = $_SERVER['HTTP_CLIENT_IP'];
- }
- else if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches))
- {
- // make sure we dont pick up an internal IP defined by RFC1918
- foreach ($matches[0] AS $ip)
- {
- if (!preg_match("#^(10|172\.16|192\.168)\.#", $ip))
- {
- $alt_ip = $ip;
- break;
- }
- }
- }
- else if (isset($_SERVER['HTTP_FROM']))
- {
- $alt_ip = $_SERVER['HTTP_FROM'];
- }
- return $alt_ip;
- }
- //The user
- $visitorIp = getUserIP();
- // Now let’s search if this IP is blackliated
- $status = array_search($visitorIp, $denied_ips);
- // another way to search??
- // $status = in_array($visitorIp, $denied_ips);
- // Let’s check if $status has a true OR false value.
- if($status !== false)
- {
- header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n");
- header("Location: http://www.smouch.net/lol");
- exit;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement