Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I find the php session start timestamp

I recall reading somewhere recently that you can obtain the server session start-time in timestamp format of the exact time a php session started for a user, but I cannot find this article again.

What I do not want is the request time (ie the time the 'REQUEST_TIME') or the "current timestamp" as of the execution of date() because (if I understand these correctly) they will change for each request and each script execution.

What I want is the time that the session was initiated on the server, and this logically can only be one moment in time.

There was apparently a was of retrieving this information.

Can anyone help?

like image 279
T9b Avatar asked May 11 '12 10:05

T9b


People also ask

When was a session created PHP?

You can start a session in PHP by using the session_start() function. This function will, by default, first check for an existing session. If a session already exists, it will do nothing, but it will create one if there's no pre-existing session available.

What is the PHP exact statement to start the session on the page?

Start a PHP Session A session is started with the session_start() function. Session variables are set with the PHP global variable: $_SESSION.

Where should a session start () function appear?

Note: The session_start() function must be the very first thing in your document. Before any HTML tags. As for your question you can start session wherever you want, but beware that session must be started before any output.


1 Answers

what's wrong with:

if (!isset($_SESSION['started'])) {
    $_SESSION['started'] = $_SERVER['REQUEST_TIME'];
}
like image 152
Vytautas Avatar answered Sep 24 '22 16:09

Vytautas