Could it be made a script that check if a user connection is breaked (for example internet connection is stopped or user is closed the browser). And not only to be displayed error message to the user but this event to be registered by my PHP script.
For now the only idia that i have is a JavaScript event onClose() of the browser but this is not the solution that I want.
I was thinking if there is a method for PHP to listening for an event of breaked connection with the user browser or something similar.
Thanks in advance.
Check if user is online
Moderator: General Moderators
Most of the time sites that show "Users Online" is usually within the last 5 minutes, they just keep a log when a user hits a page.
Then they simple select and count how many users have hit the website within the 5 or so minutes.
// EXAMPLE
Then they simple select and count how many users have hit the website within the 5 or so minutes.
Code: Select all
Select count(id) as Online FROM `logins` WHERE `timestamp` > (`timestamp` - INTERVAL 5 MINUTE)- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
PHP cannot listen to when the user "breaks connection" as the connection is broken after the PHP page is sent to the client (finishes). The common method is to assume a user as logged out if they do not access a page on the site for a certain amount of time. You may want to look at the tutorial XMLHttp tutorial (who's online example) for an example.
With the use of AJAX and timed request on the server you can get near perfect real time user information. You can also have javascript grab an image with a src pointing to an php generated image (src="image.php") the php image could update the users activeness within the system then use javascript to setTimeout to what ever time interval you want. I have used both methods they both work pretty well.
Thanks
I'll use AJAX but but the problem is if the connection is broken (supose the internet cable is unpluged or ISP having some problems). In that case the problem could be solve after 5 sec. or 1 hour (to me it is important to know about this in max 60 sec.) and I was hoping that there is something that I can use to notify PHP that there is a problem and the user is ofline for a while.
I could tell if the user is closed the browser but unpluged cable is not user dependent (and I can't use AJAX to conect to the server every 1 sec).
I could tell if the user is closed the browser but unpluged cable is not user dependent (and I can't use AJAX to conect to the server every 1 sec).
Re: Thanks
The server would poll the information, not the client. Clients who are connected would see updated information. If the client isn't connected, it only makes sense they would see outdated information.prophy wrote:I'll use AJAX but but the problem is if the connection is broken (supose the internet cable is unpluged or ISP having some problems). In that case the problem could be solve after 5 sec. or 1 hour (to me it is important to know about this in max 60 sec.) and I was hoping that there is something that I can use to notify PHP that there is a problem and the user is ofline for a while.
I could tell if the user is closed the browser but unpluged cable is not user dependent (and I can't use AJAX to conect to the server every 1 sec).
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.