I'm recoding my php script into mysqli and have most of the functions working how I want them to work except for the date and time stamp of an IP connection to my website.
Current code as follows
<?php
include 'news/admin/dbconnect.php';
$browser = $_SERVER['HTTP_USER_AGENT'];
$ip = $_SERVER['REMOTE_ADDR']; //Php retrieves the vistors IP address and stores it in the Var $ip
$visitor = gethostbyaddr($_SERVER['REMOTE_ADDR']); // Php retrives the visitors Host address and stores in the $visitor Var
$page = $_SERVER['PHP_SELF']; // Retrives page name
$sql="INSERT INTO statistics (Page, Browser, Host, IP, Date_time)
VALUES
('$page','$browser','$visitor','$ip', now())";
if (!mysqli_query($DBcon,$sql))
{
die('Error: ' . mysqli_error($con));
}
mysqli_close($con);
?>
But the issue I have is that My script is going to be running in different time zones so I have been attempting to set the time zone wrapped in the $datetime but the output in the database is empty I have searched google and the PHP manual website and I have had a few days of attempts that haven't given the desired out put of "2016-12-07 09:44:14" (this being the server time) but what I'm trying to achieve is to tell my script to get the time in e.g London time zone for myself but if the user is in China the script being configured to run on China time it gives the correct time.
My Last attempt Code:
$datetime->setTimezone(new DateTimeZone('Europe/London'));
I'll be honest here I haven't got a clue what to do I have done a load of google search terms but no dice all results in the database are empty.
Any help would be greatly appreciated.