?
Solved

Ban IP's

Posted on 2004-10-30
5
Medium Priority
?
268 Views
Last Modified: 2012-05-05
Hi all,

I had a previous question here before on banning certain IPs and redirect them to another page

I got the following code


<?php
/* put this at the top of your page */
$certain_ips = array('62.215','62.150','195.226','195.39','213.189','213.181','168.187','194.54');
foreach($certain_ips as $ip)
{
 if(substr($_SERVER['REMOTE_ADDR'], 0, strlen($ip)) == $ip)
 {
  header('Location:login.php');
  exit();
 }
else
{
header('Location:chat.php');
exit();
}
}
?>


The IPs shown are the banned IPs in my site. The problem with this code that it bans only the first two IPs but the rest still can access the site normally.

Anyone can fix that plz?

0
Comment
Question by:Souled
  • 3
  • 2
5 Comments
 
LVL 27

Accepted Solution

by:
Diablo84 earned 1000 total points
ID: 12454220
$certain_ips[8]

should be

$certain_ips

and by the looks of it you should cut out the else clause, ie:

/* put this at the top of your page */
$certain_ips = array('62.215','62.150','195.226','195.39','213.189','213.181','168.187','194.54');
foreach($certain_ips as $ip)
{
 if(substr($_SERVER['REMOTE_ADDR'], 0, strlen($ip)) == $ip)
 {
  header('Location:login.php');
  exit();
 }
}

header('Location:chat.php');
exit();

}

otherwise for everyone of the ip's its going to redirect to one or the other pages, if the ip doesnt match then it will automatically load the other page. With the above it will check all of the ips then if none of them are banned it will redirect to chat.php, not sure if thats the expected behaviour but thats how i read into it.

failing that did you try the alternative code i posted in your previous question?
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12454223
sorry that last } should not be there
0
 

Author Comment

by:Souled
ID: 12454290

I noticed that.
It gave me error when I processed it.

Now its all fine.

Thanks man

0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12454305
no problem :)
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question