[SOLVED] IP logging question.

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
thor
Forum Newbie
Posts: 2
Joined: Tue Mar 16, 2004 5:30 pm

[SOLVED] IP logging question.

Post by thor »

i was just wondering if anyone knew the PHP code that you use to log IP addresses.
kind of like when i type:
<?php echo $_SERVER['HTTP_USER_AGENT']; ?>
it will display something like:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040206 Firefox/0.8


is there some similar code where it will display the IP of the person looking at it?

if anyone knows it please post it. thanks.
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

$ip = $HTTP_REFERER;
then just add that value to a db and there you go ip == loged :)
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Code: Select all

<?php
echo '<pre>';
  // will print all $_SERVER vars
  print_r ($_SERVER);
echo '</pre>';
?>
coreycollins
Forum Commoner
Posts: 67
Joined: Sun Feb 01, 2004 1:04 pm
Location: Michigan

Post by coreycollins »

Code: Select all

$ipaddress = $_ENV["REMOTE_ADDR"];
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

$_SERVER["REMOTE_ADDR"];
User avatar
wmasterj
Forum Commoner
Posts: 40
Joined: Mon Aug 18, 2003 5:52 pm
Location: Stockholm, Sweden

Post by wmasterj »

seems like not everyone agrees or uses the same - but i can say the one before me works fine :)
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Incase three times isn't enough...a fourth!

Code: Select all

<?php
$theip = $_SERVER['REMOTE_ADDR'];
?>
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

why not kick it up a notch:

Code: Select all

<?php
$ip = "$REMOTE_ADDR";
echo $ip;
?>
Goowe
Forum Commoner
Posts: 94
Joined: Mon Mar 15, 2004 9:51 am
Location: Southeast Alaska

Post by Goowe »

Haha, everyone bands together to help someone out! I love this forum :wink:

Doesn't it seem like a lot of people are looking to track IP addresses? :roll:

I hope it's working good for you thor.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

PrObLeM wrote:$ip = $HTTP_REFERER;
then just add that value to a db and there you go ip == loged :)
I really don't think so...
tim wrote:why not kick it up a notch:

Code: Select all

<?php
$ip = "$REMOTE_ADDR";
echo $ip;
?>
would require register_globals to be on .... :?

But i do agree wiht tim's first method of getting the user's IP
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Illusionist wrote:But i do agree wiht tim's first method of getting the user's IP
Which essentially is exactaly what I posted. :wink:
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

i am aware globals has to be turned on, but we were throwing out multiple ways of getting the IP, and $REMOTE_ADDR is for sure a way (globals onn, like you said ill).

kudos
Last edited by tim on Wed Mar 17, 2004 8:55 pm, edited 1 time in total.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

It's nice when people edit their posts adding [SOLVED] in the topics when due, but please... Use the english word, and not a 'leet haxxor translated version.

Why? Plain, good curtesy and so that it's easely searchable for those looking for answers. Thanks.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

Sami wrote:Incase three times isn't enough...a fourth!

Code: Select all

<?php
$theip = $_SERVER['REMOTE_ADDR'];
?>
wow! i totally didn't see thsi the first itme i look at this thread. My apologies Sami!
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

hehe

No worries dude. :)
Post Reply