Getting a Visitor's IP Address

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

User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Cool it guys... this is a place for php discussion. The mods won't put up with comments like "I would spit in your face" Keep it clean. There's no need to be rude to eachother. That should be the end of that.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Here is a bit of my ip-banning-script (using mysql)... It simply bans ips... Should take the time to implements range-banning etc someday...

Code: Select all

CREATE TABLE mytable (
  spammer_ip INT(10) UNSIGNED NOT NULL, 
  PRIMARY KEY (spammer_ip)
);

Code: Select all

$result = mysql_query("SELECT COUNT(*) AS count FROM mytable WHERE spammer_ip=INET_ATON({$_SERVER['REMOTE_ADDR']}");
$row = mysql_fetch_assoc($result);
if ($row['count'] > 0) {
  header('Location: http://' . $_SERVER['REMOTE_ADDR']);
  exit;
}
Adding ips is done with a simple INSERT IGNORE....
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

OK guys - one more bickering comment from either of you and the topic will be locked and further action may be taken. Seriously... it's just not acceptable to speak to each other like that full-stop; in the street, in a bar, in a web forum, anywhere. It's quite simple really... if you don't want to help then don't reply. Insulting people is very bad idea here and those who've been around for long enough will be more than aware of it.

Bigun: You're number one resource to check before posting questions = http://php.net/ If it were legal I'd marry it!
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Post by Bigun »

d11wtq wrote:OK guys - one more bickering comment from either of you and the topic will be locked and further action may be taken. Seriously... it's just not acceptable to speak to each other like that full-stop; in the street, in a bar, in a web forum, anywhere. It's quite simple really... if you don't want to help then don't reply. Insulting people is very bad idea here and those who've been around for long enough will be more than aware of it.

Bigun: You're number one resource to check before posting questions = http://php.net/ If it were legal I'd marry it!
1) I make every attempt to cool off the RTFM zealots without starting a fire, they sometimes get antsy when people don't comprehend when they read something that is a new language.... literally. I hope I made a decent attempt at such. Not everyone learns by reading, some of us learn by doing, maybe one day they will all understand.

2) I'm aware of php.net, it's great for looking up functions I may use every 6 months or so, it's not a good start for beginners though.

3) This is one of the more friendly forums I've been in. I'd guess it is simply because of how quickly your responses are on flame wars. For an example of what I deal with in my most active forum - head to forums.gentoo.org and do a search for cokehabit under "Off the Wall" forums. If there is a flame war.... he's there. So, I do appreciate what you guys do. But please, to everyone else, everyone has the right to comprehend information, not just read it. And to those who answer my questions, thanks.
Last edited by Bigun on Fri Jun 30, 2006 7:29 am, edited 1 time in total.
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Post by Bigun »

timvw wrote:Here is a bit of my ip-banning-script (using mysql)... It simply bans ips... Should take the time to implements range-banning etc someday...

Code: Select all

CREATE TABLE mytable (
  spammer_ip INT(10) UNSIGNED NOT NULL, 
  PRIMARY KEY (spammer_ip)
);

Code: Select all

$result = mysql_query("SELECT COUNT(*) AS count FROM mytable WHERE spammer_ip=INET_ATON({$_SERVER['REMOTE_ADDR']}");
$row = mysql_fetch_assoc($result);
if ($row['count'] > 0) {
  header('Location: http://' . $_SERVER['REMOTE_ADDR']);
  exit;
}
Adding ips is done with a simple INSERT IGNORE....
O.o

I have a long ways to go...

I was just going to make every php page check the user's IP with a table of IP's logged, and if they match, the scripts stop cold.
Post Reply