Domanda

In my application, I want to store the user details (ip, name, duration) after login. Duration means How long the user stay as login in my application ? using php. I found IP Address using $_SERVER['REMOTE_ADDR'] And time using time() And how to find the duration ??

Thanks in advance.

È stato utile?

Soluzione

Make use of the $_SESSION Variable:

$_SESSION['timestamp'] = time();

Duration can be calculated with a simple mathematical operation. Your code (might) look like this:

$_SESSION['initial_timestamp'] = time();
$_SESSION['timestamp'] = time();
$_SESSION['duration'] = $_SESSION['timestamp'] - $_SESSION['initial_timestamp'] ;

This (should) calculate the time of the logged in user since his first log in

Altri suggerimenti

Try this:

  • You should make time entry at log on time
  • You should make time entry at log out time
  • Then calculate difference of both time.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top