PHP script to Find out IP address

Filed in Career 4 comments

We can get the IP address of any visitor by using PHP. Finding the IP address is very important requirement for many scripts where we store the members or visitors details. For security reason we can store IP address of our visitors who are doing any purchases or recording the geographical location of the visitor can be done this way. Some time based on the IP address we can redirect the browser to different areas of the site. There are many applications using this and here is the PHP code to know the IP address of any visitor to the site.

$ip=@$REMOTE_ADDR;
echo “<b>IP Address= $ip</b>”;

The above code will display this IP address= 123.16.236.148

IP address if the register_global is off
If at php.ini if register_global is set to Off then we have to change the script a bit to get the address. Here it is

$ip=$_SERVER['REMOTE_ADDR'];

bonus:

<?php
header(“X-LIGHTTPD-KBytes-per-second: 50″);
header(“X-Sendfile: /path/to/file”);
?>

Posted by thaiph   @   23 July 2009 4 comments
Tags : , ,

Share This Post

RSS Digg Twitter StumbleUpon Delicious Technorati

4 Comments

Comments
Jul 31, 2009
4:12 am

Hey! I just searched for and I found your site!,

Jul 31, 2009
4:13 am

Good Thank you It

Aug 8, 2009
2:29 am

Hi! The post is really interesting! I

Feb 2, 2010
1:25 am
#4 Biạyani :

Hi,

I happened to see your post find it quite informative. I would like to share a link where a software engineer has shared a tip on “How to get geographical location of an IP address in PHP?”. I am sharing it just for the knowledge purpose.

Here is the link:
http://www.mindfiresolutions.com/How-to-get-geographical-location-of-an-IP-address-in-PHP-815.php

Hope you find it useful and of assistance.

Thanks,
Bijayani

Leave a Comment

Previous Post
«
Next Post
»
EXULT designed by ZENVERSE  |  In conjunction with Reseller Hosting from the #1 Web Hosting Provider - HostNexus.