I have site for example www.mysite.com, with a simple login system. I use PHP and MYSQL. In session I have:
$_SESSION['user_id']
Is possible to check if the user currently has the page www.mysite.com/test.php
open?
I can use also jQuery and Ajax, but how?
In database I have for example:
Users:
id | username | is_on_test
1 | admin | 0
2 | user | 1
If user is on test.php I would like have in database in column is_on_test value 1, if isn't on test.php then should be 0.
When the user hits a page, in the header, you can check to see if $_SESSION['user_id'];
exists. If it does, write the value stored in $_SERVER["REQUEST_URI"]
to the database under that user's record. This will track the most current page they've landed on.
$sql = "Update users set lastPage='".$_SERVER["REQUEST_URI"]."' where id=".$_SESSION['user_id'];
More information on the $_SERVER
array: http://php.net/manual/en/reserved.variables.server.php
call an ajax script every 20 or 30 secs or whatever frequency u like. TEST.PHP
// fire below insertion to database
if (there exist any row of current logged in user on <table>)
update <table> set time_stamp = Now() where user_id = $_SESSION['userid']
else
insert into <table> (id,time_stamp) VALUES ($_SESSION['userid'],Now())
to display users list on ADMIN.PHP
//fire below query for displaying users
select * from <table> where time_stamp in between 'Now()-20' and 'Now()+20'
make sure that the insertion / updation queries for insert / update timestamp in every ( 20 sec or whatever) interval
How do you want to check that the user has been on the current page?
If it's through the database, you can just write a function that inserts a users details and the page they were on into the database, from the $_SESSION data...