(Dec 26, 2014 03:24 AM)Internet Security Wrote: I was searching the web and i found a few lines of code that ip lock a page to you're ip and redirect you to any link if you are not the owner.
Credits: Guinness
PHP Code
<?php
$ip = $_SERVER['HTTP_CLIENT_IP'];
if($ip!="IP Goes Here") {
Header("Location: http://google.com");
?>
I don't know if this has been seen on hf but i had to share it just in case it wasn't :)
Here's one better:
PHP Code
<?php
session_start();
// Check if hidden behind Cloudflare
if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
}
$ip = $_SERVER['REMOTE_ADDR'];
$allowed_ips = array('admin_home' => '255.255.255.255');
foreach($allowed_ips as $auth_name => $auth_ip) {
if($auth_ip != $ip) {
exit('You are not authorized to see this page.');
} else if($auth_ip == $ip) {
$_SESSION['auth_name'] = $auth_name;
$_SESSION['auth_ip'] = $auth_ip;
}
}
// Display page content down here, since we're authorized to see it.
?>Now, what if we're not at home?
PHP Code
<?php
$auth_keys = array('1234567890abcedefghijklmnopqrstuvwxyz');
$auth_attempt = $_GET['auth']; // using get, but easy change to $_POST
if(!in_array($auth_attempt, $auth_keys)) {
exit('You are not authorized to view this page.');
}
// Assumes we're authorized if we can still view page.
?>