Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Rajib Palit
Added: Jan 23, 2018 7:40 AM
Modified: Jan 23, 2018 7:41 AM
Views: 16
Tags: geo ip
How to get ip and also some data
  1.                 function getUserIP()
  2. {
  3.     $client  = @$_SERVER['HTTP_CLIENT_IP'];
  4.     $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
  5.     $remote  = $_SERVER['REMOTE_ADDR'];
  6.  
  7.     if(filter_var($client, FILTER_VALIDATE_IP))
  8.     {
  9.         $ip = $client;
  10.     }
  11.     elseif(filter_var($forward, FILTER_VALIDATE_IP))
  12.     {
  13.         $ip = $forward;
  14.     }
  15.     else
  16.     {
  17.         $ip = $remote;
  18.     }
  19.  
  20.     return $ip;
  21. }
  22.  
  23.  
  24. $user_ip = getUserIP();
  25.     $location = json_decode(file_get_contents('http://freegeoip.net/json/80.234.130.184'),true);