Home  • Programming • PHP

Detecting Visitors Real IP Address

Mobile web browser opera mini is well known for a similar IP address for different users. Detecting the real ip address of an operamini user becomes hard while using the $_SERVER["REMOTE_ADDR"] php command. But we can detect the real ip using a small snippet of php code. Use the below PHP code to detect actual ip of opera mini users.
    <?php
    function ctr_ip_tool()
    {
    $ctr=array();
    if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) && strpos($_SERVER['HTTP_X_FORWARDED_FOR'],','))
    {
    $ctr += explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
    }
    else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
    {
    $ctr[]=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    $ctr[]=$_SERVER['REMOTE_ADDR']; return $ctr;
    }
    $ctr=ctr_ip_tool();
    $ip=implode(",",$ctr);
    $ip=htmlspecialchars($ip);
    echo 'Your ip is '.$ip;
    ?>
You can test the above code in a new php file and use it anywhere as per need. Feel free to ask questions if you have any.

Comments 0


Copyright © 2025. Powered by Intellect Software Ltd