How to find IP address using PHP code | 2my4edge

22 September 2013

How to find IP address using PHP code

Here i'm going to show you that, how to find the IP address of you computer using php code, this coding is very simple one, this is actually one the basic thing in php, here i'm going to use only php code to get the real ip address of the network. let the the coding.
find ip address using php

CODE

<?php
function getRealIpAddress()
{
if (!empty($_SERVER['HTTP_CLIENT_IP']))
//check ip from internet
{
$ipadd=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
//check ip proxy
{
$ipadd=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ipadd=$_SERVER['REMOTE_ADDR'];
}
return $ipadd;
}
echo getRealIpAddress(); // display IP address
?>
yes, you can get clear idea from the above code, that  is for find the original ip address of the network. i hope this tutorial is more helpful to everyone. thank you.


RELATED POSTS :
Detect Operating System and Detect the Browser using Php






Marquee style in different manner with PHP and MySql





4 comments:

  1. On localhost i get :::1 ip address using the above php coding for getting ip address why?? plz help me

    ReplyDelete
  2. Localhost is the name of the server machine. It is used to test the network connection on the way to himself. Otherwise it is called a feedback loop. By default, IP4 address is set to 127.0.0.1 and the IP6 address :: 1 When you connect from another computer to your site's IP checking, you should get the client IP.

    ReplyDelete
  3. in result print localhost ip(127.0.0.1) i can not get my system ip plz help me..
    thank you.

    ReplyDelete

^