anyone can help me fix this code?.. its a ip redirect code based on ip.txt list.. i want ip that is in the ip.txt will be redirected to the fake site.. deny.php <?php $iplist = explode("\n",file_get_contents('ip.txt')); $ip = $_SERVER['REMOTE_ADDR']; $real_site='http://www.realpage.com'; $fake_site='http://www.fakesite.com'; if ($ip != $iplist) { Header("HTTP/1.1 301 Moved Permanently"); Header("Location:$fake_site"); } else { Header("HTTP/1.1 301 Moved Permanently"); Header("Location:$real_site"); } ?> Code (markup): thanks..
hi, explode() returns you an array. try this: if(in_array($ip, $iplist)) { // this is true, if the ip is in the iplist, ... } else { ... } Code (markup):
<?php $iplist = explode("\n",file_get_contents('ip.txt')); $ip = $_SERVER['REMOTE_ADDR']; $real_site='http://www.realpage.com'; $fake_site='http://www.fakesite.com'; if(in_array($ip, $iplist)) { Header("HTTP/1.1 301 Moved Permanently"); Header("Location:$real_site"); } else { Header("HTTP/1.1 301 Moved Permanently"); Header("Location:$fake_site"); } ?> Code (markup): using this code, i keeps going to fakesite url.. whether i include my ip or not in ip.txt
<?php $iplist = file_get_contents('ip.txt'); $ip = $_SERVER['REMOTE_ADDR']; $real_site='http://www.realpage.com'; $fake_site='http://www.fakesite.com'; if(ereg($ip,$iplist)) { Header("HTTP/1.1 301 Moved Permanently"); Header("Location:$fake_site"); } else { Header("HTTP/1.1 301 Moved Permanently"); Header("Location:$real_site"); } ?> PHP: You got them switched. No need to explode or create an array. Peace,
Woohoo.. its working now..thanks azizny.. btw, when i try this script on my other hosting, it works couple time, but suddenly it shows 404 from that hosting, what can u think off that server done?
Paul, btw.. what is the different within your script n this: my friend just give me this script <?php $ip = trim($_SERVER['REMOTE_ADDR']); $iplist = array_map('trim', explode("\n", file_get_contents('ip.txt'))); $fake_site = 'http://www.fakesite.com'; $real_site = 'http://www.realsite.com'; if(in_array($ip, $iplist)) { header('HTTP/1.1 301 Moved Permanently'); header('Location: '.$fake_site); } else { header('HTTP/1.1 301 Moved Permanently'); header('Location: '.$real_site); } ?> Code (markup): which is the most lite using system resources?..