IT Community - Software Programming, Web Development and Technical Support

visitor's IP Address

This is a discussion on visitor's IP Address within the PHP Programming forums, part of the Web Development category; Hi, How to Find a visitor's IP Address with PHP Regards, sivaraman...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-17-2007, 05:53 AM
sivaramakrishnan sivaramakrishnan is offline
D-Web Programmer
 
Join Date: Feb 2007
Posts: 74
sivaramakrishnan is on a distinguished road
Default visitor's IP Address

Hi,

How to Find a visitor's IP Address with PHP


Regards,
sivaraman
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-17-2007, 08:01 AM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,162
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default Re: visitor's IP Address

Hi,

In a PHP page, within the PHP tags, <?php ... ?>, you can retrieve the IP address of a user through the server variables array, which is contains information about the user and the server environment and is accessible from anywhere in your PHP script. To do this, you use the code $_SERVER['REMOTE_ADDR']. It works like a normal array, where REMOTE_ADDR is the key, and the IP address of the visitor is the value associated with that key.

Display The IP Address
So, if you want to display the IP Address to the user then the following page will suffice:

<?php
echo "Hello! Your IP Address is: " . $_SERVER['REMOTE_ADDR'];
?>

Exploring the $_SERVER array
You might be wondering what other information you can get from $_SERVER, well you can find out with the following script which displays all the variables in it along with their values if set, in a HTML table:

<table border="1">
<tr><th>Variable</th><th>Value</th></tr>
<?
foreach( $_SERVER as $key => $value )
{
echo "<tr><td>" . $key . "</td>";
echo "<td>" . $value . "</td></tr>";
}
?>
</table>

Finally, the following code works harder to find the true IP of the user by checking for proxies:

function userIP()
{
//This returns the True IP of the client calling the requested page
// Checks to see if HTTP_X_FORWARDED_FOR
// has a value then the client is operating via a proxy
$userIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
if($userIP == "")
{
$userIP = $_SERVER['REMOTE_ADDR'];
}
// return the IP we've figured out:
return $userIP;
}
__________________
With,
J. Jeyaseelan

Everything Possible
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Same IP Address vadivelanvaidyanathan Search Engine Optimization 0 01-23-2008 06:28 AM
Getting IP address with PHP sureshbabu PHP Programming 0 12-17-2007 07:01 AM
How to resize a visitor's browser? jeyaprakash.c HTML, CSS and Javascript Coding Techniques 4 10-14-2007 10:20 PM
How to get the MAC Address By IP address in .net? oxygen ASP and ASP.NET Programming 1 07-27-2007 05:13 AM
Visitor's browser information venkat_charya PHP Programming 2 07-19-2007 03:50 AM


All times are GMT -7. The time now is 07:32 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0