Home Laravel How to get ip address using php code?

How to get ip address using php code?

by Shahriar Sagor
get ip address using php

Today now in this post i want to show you How to get ip address using php code? Whenever we need to get the current user ip address then we can use the bellow example. I hope it will help you. We can find the client ip address by using $_SERVER variable in php.

Now you can see in the bellow example how to find the user ip address.

Example:

<?php
    function getClientIp() {
        $ipAddress = '';
        if (isset($_SERVER['HTTP_CLIENT_IP'])){
            $ipAddress = $_SERVER['HTTP_CLIENT_IP'];
        } else if(isset($_SERVER['REMOTE_ADDR'])){
            $ipAddress = $_SERVER['REMOTE_ADDR'];
        }else{
            $ipAddress = 'UnKnown';
        }
        return $ipAddress;
    }
	
    echo getClientIp();
?>

Read Also: Generate Captcha code and Validation by using BotDetect package in laravel

Thanks for read. I hope it help you. For more you can follow us on facebook

close

You may also like