sayedsohail Posted June 28, 2007 Share Posted June 28, 2007 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"; } } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.