I'd like get the time when the actual webpage has been loaded or refreshed.
I've tried http request but there is no such information.
After page is loaded ajax function checks new messages every 60 seconds. I need to show only new ones (the ones that have been posted after the page load).
Thanks a lot in advance.
As @DaveRandom mentioned:
You just need to store the result of time() in $_SESSION - e.g. $_SESSION['lastPoll'] = time();. Then every time you poll the server for new messages "SELECT * FROM messages WHERE message_time > ".$_SESSION['lastPoll'], and update the stored value with the new time()
Timestamp every message. In your AJAX function, send a parameter of the last message you already have. Return only messages newer than that. E.g., the AJAX URL you hit can look something like /get_messages.php?newer_than=1343041382
.
Assuming you store the time the message was sent in the database, and that you store it as a timestamp, you could use something like this:
When the page is loaded, you could save the current time as this:
$page_load_time = time();
Then just send the $page_load_time to your file that is loaded with AJAX, using post or get, and then in the PHP-file loaded with AJAX, you could do an SQL-query that gets all the new messages. Maybe something like this:
$sql = "SELECT * FROM `messages` WHERE `time` > '{$page_load_time}'