PHP IP Script

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
User avatar
HaVoC
Forum Commoner
Posts: 83
Joined: Sat Feb 07, 2004 7:20 am
Location: Smiths Falls, CA

PHP IP Script

Post by HaVoC »

Can anyone teach me how to get an IP with PHP if possible. It's for counter purposes.
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Re: PHP IP Script

Post by TheBentinel.com »

HaVoC wrote:Can anyone teach me how to get an IP with PHP if possible. It's for counter purposes.
I think you want:

$_SERVER['REMOTE_ADDR']

as in:

Code: Select all

print ("Your ip address is " . $_SERVER['REMOTE_ADDR']);
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Already solved, but for plain interest (?) this might be interesting.

Code: Select all

<?php
 phpinfo();
?>
Check the $_SERVER area at the bottom...
User avatar
HaVoC
Forum Commoner
Posts: 83
Joined: Sat Feb 07, 2004 7:20 am
Location: Smiths Falls, CA

Post by HaVoC »

Well, I've made this counter script. It will get the IP of the user, put it in the database and add 1. If the person comes back in the same day the script won't go up. All I need to know is how to get the user's IP.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

your question has been answered:

Code: Select all

<?php
$ip = $_SERVER['REMOTE_ADDR'];
echo "your ip is $ip";

?>
User avatar
HaVoC
Forum Commoner
Posts: 83
Joined: Sat Feb 07, 2004 7:20 am
Location: Smiths Falls, CA

Post by HaVoC »

Ok thanks, just wasn't sure. I thought that gave the address the site is on. :P
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

lol you should have tried the script out, its the address to the remote user.

your welcome. :)
Post Reply