Jump to content

[SOLVED] IP Blocking


phpretard

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.