Jump to content

Php IP security (allow requests from within uk)? and redirect the rest.


sayedsohail

Recommended Posts

Php IP security (allow requests from within uk)?

 

--------------------------------------------------------------------------------

 

Hi everyone,

 

I am just wondering how to allow requests generating within UK and restrict/redirect the rest of the users from outside world.

 

Here is the basic example i am using at the moment, but definately i need some directions to protect the contents of my website.

 

 

<?php
//Set banned IP 
$banned  = '123.123.123.123'; 

//get user IP address 
$userip = $_SERVER['REMOTE_ADDR']; 

//check for banned IP address 
if($userip == $banned){  
   echo "<BR>This IP address has been banned"; 
   exit();  
} 

//continue with script... 

?>  

 

Moreover, i found something interesting on the web, but i am not sure from where to start.

 

 

<?php
$ip_proxy=$_SERVER["HTTP_X_FORWARDED_FOR"]; 
$tnt=explode(',',$ip_proxy);
$tiny_1=explode('.',$tnt[0]);
$tiny_2=explode('.',$tnt[1]);


$filename="input.txt"; 
$lines = array(); 
$file = fopen($filename, "r"); 

while(!feof($file)) {     //read file line by line into a new array element 
    $lines[] = fgets($file, 4096); 
    }
$x = count($lines);

for ($y = 0; $y < $x; $y++) {

if((trim($lines[$y])==$tiny_1[0])||(trim($lines[$y])==$tiny_1[1]))
{	echo 'Banned';
}
else { echo "welcome";   }	

  } 	
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.