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! Quote Link to comment 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. Quote Link to comment 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.... Quote Link to comment 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(); } 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.