phpretard Posted February 19, 2009 Share Posted February 19, 2009 I only want to allow the IPs in my DB to acces my site. I think I am close but the script I have isn't working right. Any help today? <?php $query = mysql_query("SELECT * FROM adminip WHERE id='1'"); $row = mysql_fetch_array($query); $deny = array($row[content]); //print_r($deny); // << I can see ti IP arrray from the DB if (!array_key_exists($ip, $deny)) { echo("THIS SITE IS UNDERGOING CONSTRUCTION"); exit(); } ?> Thank you! Link to comment https://forums.phpfreaks.com/topic/145914-solved-ip-blocking/ Share on other sites More sharing options...
phpretard Posted February 19, 2009 Author Share Posted February 19, 2009 Right now it only allows 1 IP block...So if the IP in my DB (my ip) is the only one then everyone else is blocked. If I add an IP then it blocks NO ONE. Link to comment https://forums.phpfreaks.com/topic/145914-solved-ip-blocking/#findComment-766076 Share on other sites More sharing options...
allworknoplay Posted February 19, 2009 Share Posted February 19, 2009 All this does is get the IP from your DB, you also need to grab the IP of the web $_SERVER['REMOTE_ADDR']; And compare.... Link to comment https://forums.phpfreaks.com/topic/145914-solved-ip-blocking/#findComment-766086 Share on other sites More sharing options...
phpretard Posted February 19, 2009 Author Share Posted February 19, 2009 The ip was comming from a diferrent page (sorry I didn't include that code). $ip=$_SERVER['REMOTE_ADDR']; This works...I changed to a while loop $query = mysql_query("SELECT * FROM adminip"); while($row = mysql_fetch_array($query)) < CHANGED { $deny[]=$row[content]; // < CHANGED } //print_r($deny); << shows the array if (!in_array ($ip, $deny)) { echo("THIS SITE IS UNDERGOING CONSTRUCTION"); exit(); } Link to comment https://forums.phpfreaks.com/topic/145914-solved-ip-blocking/#findComment-766091 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.