本文介紹了如何在 PHP 中通過 IP 地址獲取時區的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我想通過 PHP 中的 IP 地址獲取時區.實際上,我有一個將在客戶端計算機上運行的應用程序.我有客戶端機器的 IP 地址.但我無法獲得每臺客戶端機器的時區.
I want to get time zone through an IP Address in PHP. Actually, I have an application which will run at the client machine. I have the IP address of the client machine. But I am not able to get the time zone for each client machine.
推薦答案
$ip = "189.240.194.147"; //$_SERVER['REMOTE_ADDR']
$ipInfo = file_get_contents('http://ip-api.com/json/' . $ip);
$ipInfo = json_decode($ipInfo);
$timezone = $ipInfo->timezone;
date_default_timezone_set($timezone);
echo date_default_timezone_get();
echo date('Y/m/d H:i:s');
有時它在本地服務器上不起作用,所以在服務器上嘗試.
Sometime it won't work on local server so try on server.
此數據來自 ip-api.com,只要您不超過 每分鐘 45 個請求 和 <強>未用于商業用途.查看他們的TOS,不是很長的一頁.
This data is coming from ip-api.com, they're free to use as long as you don't exceed 45 requests per minute and not using commercially. See their TOS, not a long a page.
這篇關于如何在 PHP 中通過 IP 地址獲取時區的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!