how do i get a users ip address?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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

how do i get a users ip address?

Postby flash_harry » 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:

Postby Hadleigh » 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.

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

Postby bobaloo » 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: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » 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


Return to “PHP coding => General”

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest