I am living in Sri Lanka. I have this code to record the current date and time when invalid login done.
$insert_query = "INSERT INTO LoginAttempt(IpAddress, LoginAt) VALUES('". $_SERVER['REMOTE_ADDR']. "', CURRENT_TIMESTAMP)";
I have uploaded to hostinger.co.uk which is free webhosting service for educational purpose.
That inserted into table successfully. It shows the date correct. But time is about 5 hours and 30 minutes less than the actual time. Is there any way to change timezone in cPanel or programmatically in the PHP script?
What I have tried;
1) addes this. but does not work! date_default_timezone_set('Asia/Colombo');
Another soulution to use DATE_ADD
function to add the particular missing hours.
What are your another ideas? Thanks
MySQL table;
CREATE TABLE LoginAttempt(
LoginId INT NOT NULL AUTO_INCREMENT,
IpAddress VARCHAR(20) NOT NULL,
LoginAt DATETIME NOT NULL DEFAULT NOW(),
PRIMARY KEY(LoginId)
);
Solution that worked!!!!
$insert_query = "INSERT INTO LoginAttempt(IpAddress, LoginAt) VALUES('". $_SERVER['REMOTE_ADDR']. "', CONVERT_TZ(NOW(), 'UTC', 'Asia/Colombo') )";