how do i get a users ip address?

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
flash_harry
New php-forum User
New php-forum User
Posts: 26
Joined: Thu Jan 16, 2003 6:05 am

Wed Feb 05, 2003 6:48 am

Subject is fairly self explanitory.
I tried doin this -

$host = $REMOTE_ADDR;
print "$host";

but apparently it isn't that simple.

Hadleigh
New php-forum User
New php-forum User
Posts: 32
Joined: Tue Feb 04, 2003 10:32 am
Location: UK
Contact:

Wed Feb 05, 2003 7:38 am

Hi,

There are a great many things you can get, try putting this in a script to see the full list.

<?
phpinfo();
?>

To pull one out simply put:
<?
$ip_address=getenv(REMOTE_ADDR);
echo"$ip_address";
?>
replace REMOTE_ADDR to get the others.

regards,

Hadleigh.
A learned man is an idler who kills time by study.

George Bernard Shaw (1856-1950)

bobaloo
New php-forum User
New php-forum User
Posts: 11
Joined: Sat Feb 01, 2003 11:34 am

Wed Feb 05, 2003 9:39 am

or you could put:

<?PHP
$ip_addy = $_SERVER['REMOTE_ADDR'];
echo $ip_addy;
?>

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

Wed Feb 05, 2003 4:31 pm

just having $REMOTE_ADDR will only work if register_globals is turned on. PHP 4.2 and higher have this turned off by default.

bobaloo's example $_SERVER['REMOTE_ADDR'] should work

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest