Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Ban IP's

Posted on 2004-10-30
5
Medium Priority
?
265 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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

609 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