SQL PHP HTML ASP JavaScript articles and free scripts to download
PHP Static & Dynamic IP

PHP script to Find out IP address

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 doing any type of transaction online. We can using the IP address to find out geographical location of the visitor. 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.

What is my IP address ?

Here is the code to display your ip address.

$ip=$_SERVER['REMOTE_ADDR'];
echo "IP address= $ip";

The above code will display this IP address= 54.242.112.71

$_SERVER is an array and it contains lot of information as supplied by server and one of the element is 'REMOTE_ADDR' which gives us the IP address. Here is another example of getting the server name using $_SERVER

$_SERVER['SERVER_NAME'] = www.plus2net.com

You can display all other elements of Array by using display elements of array. Here is a sample code.

while (list ($key, $val) = each ($_SERVER)) {
$key -> $val
}

Storing IP address in MySQL database table

After collecting the IP address we can store in mysql table. Along with IP address we can store referrer , browser details etc.
We can convert the dot formatted IP address to number by using ip2long function and store in MySQL database.
This is IPV4 address and for next generation IPV6 address we have to change the field length of our database table

referrer to your site by using PHP.


How to get IP address in ASP ?

Number of User Comments : 25


Google+
John15-06-2009
I need a script similar to that of the one at tracemyip.com
anto17-06-2009
nice.. can you show how to get the full details for the network addressed including the gateway and sub-net mask? thank you
Spirit20-06-2009
You cannot find out somone's subnet mask, or gateway externally. Both are part of their internal network, all of which shares the same external IP.
Myles13-07-2009
To John - Thanks for that info, now go and make it.
Anto, type ipconfig in msdos or as is probably more apt.....winipcfg in START then RUN.
ajay joshi19-09-2009
thanx.. can you show how to get the full details for ip tracing/ip trapping
CanadaWest21-09-2009
You say,
"recording the geographical location of the visitor can be done this way"
How can I get the user's geographical location to redirect the user to the correct info for their region?
smo21-09-2009
Once IP address is known then the location can be collected by using available geo location tables. These tables are available at cost and can be updated regularly.
gizmo28-11-2009
can you show how to get the full details for the network addressed
santosh30-12-2009
how to run the above code?...
Pham Nguyen01-01-2010
why do i use the code $ip=@$REMOTE_ADDR; on localhost. $ip=127.0.0.1. Please lest me know how about on the host server?
Krishnat31-01-2010
i want to design cyberoam through php..so please tell me some guideline
PHP Developer18-03-2010
Looking to find out how to look up who owns the IP and what the IP owner's address is. Thanks!
kiran malvi15-04-2010
This ip function are most usefull for anyone.
so thanks.
Mahendra Rajgude07-07-2010
Really useful info. Thanks.
Mutahir shah22-10-2010
Please someone could provide me how to conver IP address to address where the user is loged in.
John11-01-2011
Thanks ....it worked.
Michael11-02-2011
I have 14 tracts that I want the visitors to my website to be able to send to their friends. Please can you let me have a script attached to be bottom of the page telling visitors to send to their friends.
sparky23-08-2012
I am trying to determine where to place this piece of code in my .php file. The page has html and php code inside of it. I would like to track IP addresses and have them stored to my .csv file, which I already have working with fwrite.

Hitender05-12-2012
how to fetch the ip address of user filling a form in php sites?
I want the exact coding please let me know about this....
HridoY63603-04-2013
Why those code shows different ips in differnt time.. Even i am visiting this page with same network and same phone and even same browser? Plz answer me.
Subhendu06-04-2013
Your ISP assign you different IP each time you start connecting to internet. This is known as dynamic IP. In contrast if you take static IP from your ISP , they will charge more for this but you can have your own services like VOIP, web hosting etc.
akhil22-04-2013
i want to know the ip address of the computer, who chat with me from another network ?
Anindya18-05-2013
how to fetch permanent IP address of a computer..?? is it possible..??
George19-05-2013
you can also use a ip geo-location pluggin like the one in bricksett cms. it takes users ip address and then gives you the country code.
mohsen02-09-2013
thank you...

it's short and useful.

Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



Join Our Email List
Email:  
For Email Newsletters you can trust
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer