Jump to content
xisto Community
Sign in to follow this  
yoofus

Showing A Users Ip Address In Php

Recommended Posts

In this simple tutorial I will explain how to show a users IP address in your website statistics.

Open the file you would like to show the IP in, and insert this code where you want it to show:

<?php echo $_SERVER["REMOTE_ADDR"]; ?>

An IP Address whould show up. If you would like to have text infront of the IP, for example, IP Address: Blah Blah. Type:

IP Address: <?php echo $_SERVER["REMOTE_ADDR"]; ?>

Make sure to save the file as '.php' format, otherwise the code will not work.

Share this post


Link to post
Share on other sites

Well thats nice and easy for the n00bs, lol. However an alot better cleaner way of doing it is like this...

<?php

$ip = getenv('REMOTE_ADDR');

echo "<p>IP: $ip</p>";

?>

then with that way you can also do thing like HTTP_USER_AGENT or HTTP_GET_VARS all in one variable/function. Make sense? :)B)

Share this post


Link to post
Share on other sites

I know. However there is still an even easier way of doing it than that. Just go...

<?php echo "IP: $REMOTE_ADDR"; ?>
Thats even shorter. :)B)

Share this post


Link to post
Share on other sites

No problem, your always welcome as everyone is. B) Thanks for the rep point too. :) :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.