Friday, 7 October 2022

How to get geo location on registration in laravel?

Get Geo - location details 

 function getLocationInfoByIp(){

    $client  = @$_SERVER['HTTP_CLIENT_IP'];

    $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];

    $remote  = @$_SERVER['REMOTE_ADDR'];

    $result  = array('country_name'=>'', 'time_zone'=>'');

    if(filter_var($client, FILTER_VALIDATE_IP)){

        $ip = $client;

    }elseif(filter_var($forward, FILTER_VALIDATE_IP)){

        $ip = $forward;

    }else{

        $ip = $remote;

    }    

    $ip_data = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ip));    

      

    if($ip_data && $ip_data->geoplugin_countryName != null){

        $result['country_name'] = $ip_data->geoplugin_countryName;

        $result['time_zone'] = $ip_data->geoplugin_timezone;

    }

    return $result;

}

No comments:

Post a Comment

Machine Learning - Potato Leaf Disease Prediction

Step 1: import numpy as np import pandas as pd import splitfolders import matplotlib.pyplot as plt import tensorflow as tf from tensorflow i...