2

I am using cakephp framework here i also successfully get the client ip

$client_ip=$this->RequestHandler->getClientIp();
$this->set(compact('client_ip'));
echo $client_id; e.g. 127.0.0.1
$tags = get_meta_tags("http://www.geobytes.com/IpLocator.htm?GetLocation&template=php3.txt&IpAddress=$client_ip");

When i print the array

echo "<pre>";
print_r($tags)

my array becomes empty.

kunal
  • 4,122
  • 12
  • 40
  • 75
  • 1
    Possible duplicate of [Google IP Geolocation API](http://stackoverflow.com/questions/13793655/google-ip-geolocation-api) – Sherif Sep 03 '16 at 07:36
  • Possible duplicate of [How to find timezone ID from IP address/country name in PHP?](https://stackoverflow.com/questions/11219635/how-to-find-timezone-id-from-ip-address-country-name-in-php) – Matt Johnson-Pint Jul 13 '17 at 18:56

2 Answers2

1

Here i found the solution:

$user_ip = getenv('REMOTE_ADDR'); 
$geo = unserialize(file_get_contents("http://www.geoplugin.net/php.gp?ip=$user_ip")); 
$country = $geo["geoplugin_countryName"]; 
$city = $geo["geoplugin_city"];
Tigger
  • 8,980
  • 5
  • 36
  • 40
kunal
  • 4,122
  • 12
  • 40
  • 75
  • Dear ryan. This website is used in many countries not for single country.so we can find the timezone dynamically.Hope you understand – kunal Sep 03 '16 at 17:43
0

An empty array from get_meta_tags() just means the file doesn't contain any meta tags. Try visiting the URL directly and inspect the HTML. It may not be what you think it is.

On a side note:

You should always use var_dump() for debugging variables.

Community
  • 1
  • 1
Sherif
  • 11,786
  • 3
  • 32
  • 57
  • Can you Please how to get the timezone based on client id – kunal Sep 03 '16 at 07:16
  • When i remove the get_meta_tags. I get the following output : http://www.geobytes.com/IpLocator.htm?GetLocation&template=php3.txt&IpAddress=127.0.0.1 – kunal Sep 03 '16 at 07:20
  • Based on the client id or do you mean based on the client ***IP***? – Sherif Sep 03 '16 at 07:30
  • Client IP address I already get the Client_ip by this function $this->RequestHandler->getClientIp(); – kunal Sep 03 '16 at 07:32
  • But i dont know how to get the timezone of that IP address – kunal Sep 03 '16 at 07:34
  • You would have to rely on looking up the IP address in a geoip database that also provides relevant timezone information or using a service like the one you appear to be *trying* to use. However, it should probably be noted that an IP address isn't likely to provide you with any accurate form of timezone information. The assumption you're making here is that the IP address whois information, accurately represents the user's physical location. That's not always the case. – Sherif Sep 03 '16 at 07:35
  • I want to show the timezone in my website that website is accessed in many country. I want when user from US accessed the website the timezone of US will be displayed and accessed from India the timezone of india will be shown . If you have any code regarding my problem please share it sherif . Thanks in advance :) – kunal Sep 03 '16 at 07:40
  • 1
    Don't bother. Just send everything as a Unix timestamp to the client and have javascript format it to a date. The browser already knows what timezone it's in. There's no need for you to do all the juggling. Timezones are evil, complicated, confusing, cumbersome, convoluted, inaccurate, contradicting, evolving, perplexing artifacts of anarchy. *tl;dr;* Avoid them like the plague. – Sherif Sep 03 '16 at 07:43