0

I am using codeigniter and I want to get users current date and time.

Getting error 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');
JHobern
  • 866
  • 1
  • 13
  • 20
hime
  • 63
  • 4
  • 11

0 Answers0