Getting visitors IP address in php?

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
lc
Forum Contributor
Posts: 188
Joined: Tue Apr 23, 2002 6:45 pm
Location: Netherlands

Getting visitors IP address in php?

Post by lc »

is there a way to get the visitor's (the person requesting a page) IP number as a variable in PHP?
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

$ip = $_SERVER['REMOTE_ADDR']; // grabs IP address
$hostname = gethostbyaddr($ip); // resolves hostname from IP address
lc
Forum Contributor
Posts: 188
Joined: Tue Apr 23, 2002 6:45 pm
Location: Netherlands

Post by lc »

Coolness.. I'm going to try it out right now... had a problem with someone using 1 of my scripts.

He had someone entering 200 messages a day in a gb I wrote... Now I can rewrite it to store the IP address along with everything... and block it after it left it's 1 allowed message.

Thx.. you's a big help
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

$ip = getenv('REMOTE_ADDR');

works, as well.
Post Reply