Is it possible to ban local IPs?!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Black Majin
Forum Newbie
Posts: 22
Joined: Wed Jul 16, 2003 12:51 pm
Location: Garland, Texas

Is it possible to ban local IPs?!

Post by Black Majin »

<?php
$banned_ip = array();
$banned_ip[] = '65.65.82.217';

foreach($banned_ip as $banned) {
$ip = $_SERVER['REMOTE_ADDR'];
if($ip == $banned){
echo "You are banned. Now how do you like dem apples.";
exit();
}
}
?>

I put that at the top of the page after the HTML tag. It works just fine. But for various reasons, I'd like to ban somone in my household from going to my site without banning my computer also. So is there a way to do this? I tried just putting in the local IP for his computer but it didnt work. Help!!
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

Code: Select all

<?php
$ip = $_SERVER["REMOTE_ADDR"];

if ($ip == "the ip of the machine") {
echo "banned";
}
?>
hmm, maybe i'm missing something?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Is the setup such that both computers access the internet through a router/switch? If so, there's no way to do what you want, since neither of your computers are going out on the internet, the router's going out for you. So, both your and the other computer will have the same IP.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

User authentication is a good solution.
Black Majin
Forum Newbie
Posts: 22
Joined: Wed Jul 16, 2003 12:51 pm
Location: Garland, Texas

Post by Black Majin »

pickle wrote:Is the setup such that both computers access the internet through a router/switch? If so, there's no way to do what you want, since neither of your computers are going out on the internet, the router's going out for you. So, both your and the other computer will have the same IP.
But isnt there like a way I can make it so it will find the internet IP AND the local IP so I can ban my internet IP but only my brothers local IP from his computer. Come on theres gotta be a way.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Sami wrote:User authentication is a good solution.
That's a way. 8)
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

or just check the ip, if it is yours, then ask for a secret key to load the site :D
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

pssst, that's not actually mine ;) .. just another Dune lover, I guess.. :lol:
Post Reply