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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.