php" file_get_contents()"返回“无法打开流:"

时间:2016-11-09 10:32:49

标签: php

我正在使用codeigniter,我想让用户获得当前的日期和时间。

获取错误Message: file_get_contents(http://ip-api.com/json/[ip]): failed to open stream: An attempt was made to access a socket in a way forbidden by its access permissions.

$xipx = $_SERVER['REMOTE_ADDR'];
$xdetails = json_decode(file_get_contents("http://ip-api.com/json/{$xipx}"));
$timex = $xdetails->timezone;

$UTC = new DateTimeZone("UTC");
$newTZ = new DateTimeZone($timex);
$date = new DateTime( "now" , $UTC );
$date->setTimezone( $newTZ );
echo $date->format('Y-m-d H:i:s');

0 个答案:

没有答案