You will have to use Javascript; PHP is executed on the server - which is not the same as the user's browser or location.
For example:
(function() {
var url = '/some/file.php?date=' + new Date();
fetch(url, {
method: 'GET',
mode: 'no-cors'
})
.then(response() => console.log(response))
.catch(error => console.error('Could not complete request:', error));
})();
Then in the Server you can process the request:
<?php
// request date contains the date from our JS request
if( $_REQUEST['date'] )
{
// format it how you want it
$date = date('j M Y h:i:s a', $_REQUEST['date']);
// check and make sure variable exists
if( $date )
{
// connect to mysql (this is not recomended... better to use some sort of library)
$mysql = new mysqli('localhost', 'root', '', 'site');
// safely store it with prepared statements
$stmt = $mysql->prepare('INSERT INTO visits (visist_time) VALUES (?)');
if($stmt = $stmt->bind_param('d', $date))
{
// this will execute the query
$stmt->execute();
}
}
}
This is not a perfect answer; I am not sure why you want to get a timestamp for users who visit, but that will in theory be able to record timestamps every time the JS script is loaded.