client IP address

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

webtekie
New php-forum User
New php-forum User
Posts: 9
Joined: Thu Apr 10, 2003 10:33 am
Location: brooklyn, ny
Contact:

client IP address

Postby webtekie » Wed Apr 16, 2003 6:03 am

Hi,

How can I get IP address of a client that logged in into my site?

thanks,
webtekie

User avatar
bezmond
Moderator
Moderator
Posts: 312
Joined: Sat Apr 05, 2003 4:33 am
Location: Mansfield, UK
Contact:

Postby bezmond » Wed Apr 16, 2003 6:22 am

$ip = $_SERVER['REMOTE_ADDR'];

Andrew

sleepingdanny
New php-forum User
New php-forum User
Posts: 13
Joined: Mon Mar 17, 2003 6:38 am

Postby sleepingdanny » Thu Apr 17, 2003 1:40 am

You can use this code: :arrow:

$file="Path To Log File"; #/home/site.com/...
$fp=fopen($file,'a') or die("Couldn't Log!");
fputs($fp,"$REMOTE_ADDR\n");
fclose($fp);

It will open the log file and will add the visitor IP address to it. :P

If you'll do what Andrew suggested you will only see your own IP address. :roll:

User avatar
bezmond
Moderator
Moderator
Posts: 312
Joined: Sat Apr 05, 2003 4:33 am
Location: Mansfield, UK
Contact:

Postby bezmond » Thu Apr 17, 2003 2:05 am

really? I was under the impression that displayed the IP of that PC... it's used in a browsing counter that I use, and it stores the IP of that clients PC every time.

Andrew

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Thu Apr 17, 2003 11:16 am

sleepingdanny wrote:You can use this code: :arrow:

$file="Path To Log File"; #/home/site.com/...
$fp=fopen($file,'a') or die("Couldn't Log!");
fputs($fp,"$REMOTE_ADDR\n");
fclose($fp);

It will open the log file and will add the visitor IP address to it. :P

If you'll do what Andrew suggested you will only see your own IP address. :roll:


$REMOTE_ADDR and $_SERVER['REMOTE_ADDR'] are the same thing. Only thing is $REMOTE_ADDR will only work if register_globals is turned on which is the not so smart way to run a server.


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 2 guests