Trying to implement the following php script that i found at php.net. My question how to mod the following script so that it redirects the users to index.php page if it is found that the ip is black listed. $result=Array(); $dnsbl_check=array("bl.spamcop.net", "list.dsbl.org", "sbl.spamhaus.org"); if ($ip) { $quads=explode(".",$ip); $rip=$quads[3].".".$quads[2].".".$quads.".".$quads[0]; for ($i=0; $i<count($dnsbl_check); $i++) { if (checkdnsrr($rip.".".$dnsbl_check[$i].".","A")) { $result1[]=Array($dnsbl_check[$i],$rip.".".$dnsbl_check[$i]); } } } aeroguy is online now Add to aeroguy's Reputation Report Post Edit/Delete Message
if you havn't produced any HTML output yet, you can use header("Location:/path/to/new/location.php"); Code (markup):
Something like : <?php $ip = getenv("REMOTE_ADDR"); function is_blacklisted($ip) { $dnsbl_check=array("bl.spamcop.net", "list.dsbl.org", "sbl.spamhaus.org"); if ($ip) { $quads=explode(".",$ip); $rip=$quads[3].".".$quads[2].".".$quads[1].".".$quads[0]; for ($i=0; $i<count($dnsbl_check); $i++) { if (checkdnsrr($rip.".".$dnsbl_check[$i],"A")) { $listed.=$dnsbl_check[$i]." "; } } if ($listed) { return $listed; } else { return FALSE; } } } $j=is_blacklisted($ip); if ($j) { header("Location:/index.php"); } else { //do something else } ?> PHP:
^^^ Exactly. You just need to do it when the ip is registered as a blacklisted ip. If that doesn't work, IE you get an error message that sais "HEADERS ALREADY SENT..." something like that, you can use this code instead. It is through javascript, but it still works. echo "<script language="javascript">location.href='/path/to/file/file.php';</script>"; PHP:
BTW this wont work anyway : header("Location:/index.php"); PHP: The correct one is header("Location: /index.php"); PHP: Check the space between : and /