Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Showing A Users Ip Address In Php
yoofus
post Mar 26 2005, 09:57 AM
Post #1


Member [Level 1]
****

Group: Members
Posts: 74
Joined: 25-March 05
From: England
Member No.: 4,906



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:

CODE

<?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:

CODE

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


Make sure to save the file as '.php' format, otherwise the code will not work.
Go to the top of the page
 
+Quote Post
maddog39
post Mar 26 2005, 07:46 PM
Post #2


Super Member
*********

Group: Members
Posts: 208
Joined: 27-January 05
From: LI, New York
Member No.: 3,448



Well thats nice and easy for the n00bs, lol. However an alot better cleaner way of doing it is like this...
[CODE]
<?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? wink.gif biggrin.gif
Go to the top of the page
 
+Quote Post
yoofus
post Mar 26 2005, 07:51 PM
Post #3


Member [Level 1]
****

Group: Members
Posts: 74
Joined: 25-March 05
From: England
Member No.: 4,906



I know maddog, but this tutorial was for beginners!
Go to the top of the page
 
+Quote Post
maddog39
post Mar 26 2005, 08:24 PM
Post #4


Super Member
*********

Group: Members
Posts: 208
Joined: 27-January 05
From: LI, New York
Member No.: 3,448



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

<?php echo "IP: $REMOTE_ADDR"; ?>

Thats even shorter. wink.gif biggrin.gif
Go to the top of the page
 
+Quote Post
yoofus
post Mar 26 2005, 08:44 PM
Post #5


Member [Level 1]
****

Group: Members
Posts: 74
Joined: 25-March 05
From: England
Member No.: 4,906



Thanks, I didn't know about that way. You get a reputation point for helping me smile.gif
Go to the top of the page
 
+Quote Post
maddog39
post Mar 26 2005, 09:39 PM
Post #6


Super Member
*********

Group: Members
Posts: 208
Joined: 27-January 05
From: LI, New York
Member No.: 3,448



No problem, your always welcome as everyone is. smile.gif Thanks for the rep point too. wink.gif biggrin.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Configuring Dns Settings For Website(1)
  2. Building An Address Book With Java(1)
  3. Asking Users To Confirm If They Wish To Leave The Page(5)
  4. How To: Have Opera Check C-panel Webmail(1)
  5. Dynamic Signature - Yet Another Way To Do It(0)
  6. Encode Your Email Address(5)
  7. Opening Nat On Your Xbox - Upnp With Netgear(0)
  8. Verifying Your Email Address(0)
  9. How To Control Other Users’ Privileges (microsoft Windows Steadystate 2.5)(1)
  10. How To Disable Firefox's Awesome Bar(7)


 



- Lo-Fi Version Time is now: 6th September 2008 - 04:46 PM