Solved

ON EXIT

Posted on 2004-08-07
6
181 Views
Last Modified: 2008-03-06
I need to know when the user close my page (without logging of), Is there any way to do this in PHP?

Thanks in advance
0
Comment
Question by:ferassh
6 Comments
 
LVL 4

Accepted Solution

by:
BrianPap22 earned 25 total points
ID: 11742145
Absolutely not.  PHP is a pure server-side language.  HTTP is a stateless protocol, so it only communicates with the browser whenever they request a page.  You will not know when they close the page.

You might try Javascript, which is a client-side language.
0
 
LVL 27

Assisted Solution

by:Diablo84
Diablo84 earned 25 total points
ID: 11742366
The only way you can do this is by launching a popup in the onunload body event which runs a small script to handle telling you that they have closed the page however i strongly advise against this as it can be very annoying from the users pespective.

In php it is usually handled with timeouts, if a user is inactive for more then 2 minutes for example they can be classed as no longer browsing the site.
0
 
LVL 2

Expert Comment

by:leeprovoost
ID: 11744477
what do you want to achieve? perhaps there's another solution for your problem :-)
0
 
LVL 4

Expert Comment

by:macgruder
ID: 11745319
have the page constantly refresh itself through Javascript every 10 secs or so
when the page connects have it write to a database some page id, and timestamp
have the database regularly checked
if the page id doesn't appear in the db within a certain timestamp then it's probably no longer connected

This is a solution to what you are trying to do, but not saying that it's a good idea :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question