How can I store the user details (ip, name, duration) after login using php ?

StackOverflow https://stackoverflow.com/questions/22754211

  •  24-06-2023
  •  | 
  •  

سؤال

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.

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

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.
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top