If this site has a login script / log out script, you can
- When the user finishes the session (logs out), you can run a refresh request with the username of the user's session and timestamp
- If the userβs session time (perhaps he leaves the website but doesnβt leave it), you can run a query with the username and timestamp in order to have data when the user timeout and session duration for.
- If a user logs in to this session, the username / user name entered will store the session data in the database.
These are just some of the ways to do this (the first two ways that come to mind). Take a look at PHP sessions for further assistance. Also for the query material, see PHP PDO Again, I want to repeat that these are the first two things that come to mind, and with the Information I provided, I came up with the following recommendations. Hope this is some help / "AH - HAH!" moment. Enjoy sir.
Change 1
If you accidentally try to run a request when the browser is closed / the user clicks a link to an external domain, then no, because the commented comment cannot trust the browser to notify the server. But, as I wrote above the editing, you could use the above methods to get closer to what you requested.
Also be sure to read the OWAPS PHP security cheat sheet . This and the PHP user manual should be your best friends: D
Again, I hope this will be useful to you!
Happy coding :)
source share