I’m new to this site, I have been coding a script to block certain IPs from a website, the thing is, it all works with the first IP in the column, say for example the database looks like this:
http://gyazo.com/290bc2b9ef77d5b985ddd675ba0c08d1
Then only the first IP, in this case 86.70.*. would be redirected to the banned page,
If someone could please help me get my php script working:
<?php
mysql_connect("localhost", "root", "password") or die(mysql_error());
mysql_select_db("bans") or die(mysql_error());
$query = mysql_query("SELECT * FROM `database`");
$row = mysql_fetch_array($query);
$ip = $_SERVER['REMOTE_ADDR']; //Gets the users IP adress
$deny = array( $row[ip]);
if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) {
header("Location: http://gabbo.org.uk/banned.php"); //What page shall the bans be sent to?
exit();
}?>
I would be very grateful!
E. Rosier
Small change in your logic.
Working
When a user with an IP Address of
192.168.1.1attempts to access your page and your ban list of MySQL has it, it surely returns some rows, which is greater than1. That way, the header gives a301 Permanent Redirectionto the browser to the banned page.