473,404 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

How to detect user leaving site?

Can this be done without client-side scripting? I thought sessions
might be the answer but after some testing found that sometimes the
old session data remained even after the user left the site and
returned. Just had an idea, though. Perhaps I could access the users
Referrer header?
Jun 2 '08 #1
18 9020
sebastian schreef:
Can this be done without client-side scripting? I thought sessions
might be the answer but after some testing found that sometimes the
old session data remained even after the user left the site and
returned. Just had an idea, though. Perhaps I could access the users
Referrer header?
Hi Sebastian,

I think you cannot detect this without JavaScript.
If somebody goes somewhere else, your server is not notified.
You can only try this via JavaScript.

Referer:
And I don't see how the Referer header can help you out.
It is send to the next site (if send at all).

Session:
No go either.
A Session is nothing more than a piece of data on the server that is
linked to a certain visitor via a PHPSESSID (via cookie/url/form).
I don't see how they can help you with this.

So bottomline, bad luck.
You need JavaScript (or some other clientside technology, like an JAVA
applet).

Regards,
Erwin Moller
Jun 2 '08 #2
Erwin Moller wrote:
sebastian schreef:
>Can this be done without client-side scripting? I thought sessions
might be the answer but after some testing found that sometimes the
old session data remained even after the user left the site and
returned. Just had an idea, though. Perhaps I could access the users
Referrer header?

Hi Sebastian,

I think you cannot detect this without JavaScript.
If somebody goes somewhere else, your server is not notified.
You can only try this via JavaScript.

Referer:
And I don't see how the Referer header can help you out.
It is send to the next site (if send at all).

Session:
No go either.
A Session is nothing more than a piece of data on the server that is
linked to a certain visitor via a PHPSESSID (via cookie/url/form).
I don't see how they can help you with this.

So bottomline, bad luck.
You need JavaScript (or some other clientside technology, like an JAVA
applet).
Correct me if I'm wrong, but if user left his site, and then returned
refer would point to the other site. So detecting refer value could
possibly help the problem.

@Sebastian
Refer it's send by the user, so can't be trusted. You can use it
to improve the functionality of the site, but don't use it to any
critical checks (like access controll ect.).

It's also possible, that refer will be empty, when user types in the url
or opens new window in 'new tab' (not sure about that though).

best regards
Piotr N
Jun 2 '08 #3
Erwin Moller wrote:
sebastian schreef:
>Can this be done without client-side scripting? I thought sessions
might be the answer but after some testing found that sometimes the
old session data remained even after the user left the site and
returned. Just had an idea, though. Perhaps I could access the users
Referrer header?

Hi Sebastian,

I think you cannot detect this without JavaScript.
If somebody goes somewhere else, your server is not notified.
You can only try this via JavaScript.

Referer:
And I don't see how the Referer header can help you out.
It is send to the next site (if send at all).

Session:
No go either.
A Session is nothing more than a piece of data on the server that is
linked to a certain visitor via a PHPSESSID (via cookie/url/form).
I don't see how they can help you with this.

So bottomline, bad luck.
You need JavaScript (or some other clientside technology, like an JAVA
applet).

Regards,
Erwin Moller
And even Javascript doesn't necessarily tell you. Closing the browser,
for instance, will not execute javascript.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 2 '08 #4
Regards,
Erwin Moller
Something tells me that you are not, in fact, Erwin Moller. If not,
please do not reply to my posts. The fact that you would masquarade as
another user is ridiculous. Pitiful.

- Sebastian

Jun 2 '08 #5
sebastian wrote:
>Regards,
Erwin Moller

Something tells me that you are not, in fact, Erwin Moller. If not,
please do not reply to my posts. The fact that you would masquarade as
another user is ridiculous. Pitiful.

- Sebastian
^^

That kinda made my day :)

best regards
Piotr N
Jun 2 '08 #6
In our last episode,
<e8**********************************@b1g2000hsg.g ooglegroups.com>, the
lovely and talented sebastian broadcast on comp.lang.php:
Can this be done without client-side scripting?
No.

Unless someone develops a psychic server.

--
Lars Eighner <http://larseighner.com/us****@larseighner.com
Countdown: 256 days to go.
Jun 2 '08 #7
sebastian wrote:
>Regards,
Erwin Moller

Something tells me that you are not, in fact, Erwin Moller. If not,
please do not reply to my posts. The fact that you would masquarade as
another user is ridiculous. Pitiful.

- Sebastian

That is the real Erwin Moller.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 2 '08 #8
>That is the real Erwin Moller.

Ok, thanks for the clarification. The email address just looked
suspicious. =)
>Correct me if I'm wrong, but if user left his site, and then returned
refer would point to the other site. So detecting refer value could
possibly help the problem.

Great, I'll try that out then.
>Refer it's send by the user, so can't be trusted. You can use it
to improve the functionality of the site, but don't use it to any
critical checks (like access controll ect.).

It's just to display a welcome message, so no problem there.
>It's also possible, that refer will be empty, when user types in the url
or opens new window in 'new tab' (not sure about that though).

Right. Well, thanks for all of the suggestions.

Regards,
- Sebastian
Jun 2 '08 #9
sebastian wrote:
>>Correct me if I'm wrong, but if user left his site, and then returned
refer would point to the other site. So detecting refer value could
possibly help the problem.

Great, I'll try that out then.
Just to make sure we talk about the same. Refer header will contain the
other site url, if users comes from other site. If he hits back button
it won't work. Only with links.

best regards
Piotr N
Jun 2 '08 #10
Yes, of course. Again, this isn't a very critical feature - it just
needs to work for the standard case. Thank you for the input.

- Sebastian

Jun 2 '08 #11
sebastian wrote:
>>That is the real Erwin Moller.

Ok, thanks for the clarification. The email address just looked
suspicious. =)
>>Correct me if I'm wrong, but if user left his site, and then returned
refer would point to the other site. So detecting refer value could
possibly help the problem.

Great, I'll try that out then.
Only works if 1) he comes back to your site, and 2) his browser and
firewall are correctly reporting the HTTP_REFERER. It will fail for
those who do not forward HTTP_REFERER.
>>Refer it's send by the user, so can't be trusted. You can use it
to improve the functionality of the site, but don't use it to any
critical checks (like access controll ect.).

It's just to display a welcome message, so no problem there.
>>It's also possible, that refer will be empty, when user types in the url
or opens new window in 'new tab' (not sure about that though).

Right. Well, thanks for all of the suggestions.

Regards,
- Sebastian
I'd just display the welcome message on your home page. People are used
to it by now.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 2 '08 #12
sebastian schreef:
>Regards,
Erwin Moller

Something tells me that you are not, in fact, Erwin Moller. If not,
please do not reply to my posts. The fact that you would masquarade as
another user is ridiculous. Pitiful.

- Sebastian
Hi Sebastian,

Was my answer so darn stupid that you confused me with that
imposternoob? And yes, masquarading as another user is totally stupid.
I still have no clue why that happened, but the guy seems away now.
I hope it stays that way.

Anyway, to the original subject: I still fail to see the use of using
the referer header.

For clearity's sake, this is what I found from w3c.

from http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
14.36 Referer

The Referer[sic] request-header field allows the client to specify, for
the server's benefit, the address (URI) of the resource from which the
Request-URI was obtained (the "referrer", although the header field is
misspelled.) The Referer request-header allows a server to generate
lists of back-links to resources for interest, logging, optimized
caching, etc. It also allows obsolete or mistyped links to be traced for
maintenance. The Referer field MUST NOT be sent if the Request-URI was
obtained from a source that does not have its own URI, such as input
from the user keyboard.

Referer = "Referer" ":" ( absoluteURI | relativeURI )

Example:

Referer: http://www.w3.org/hypertext/DataSources/Overview.html
So what is IN the referer header?
(If it is set by the browser, and not stripped by some router as Jerry
already warned for)
Well, nothing more that the URI of the page that contained the url you
are visiting now.
IF that URL is on another site (domain), the fact that it is clicked
will never reach the original server.

So I still don't see how this can be used to detect that a user is
leaving your site. Yes, of course the second server can see it, when the
right referer header is sent, but NOT the server of the OP.

Or am I missing something completely here?

Regards,
Erwin Moller

PS: I read the only goal of this exercise was to say 'welcome back'. A
simple cookie might make more sense to do that.
Jun 2 '08 #13
Piotr schreef:
Erwin Moller wrote:
>sebastian schreef:
>>Can this be done without client-side scripting? I thought sessions
might be the answer but after some testing found that sometimes the
old session data remained even after the user left the site and
returned. Just had an idea, though. Perhaps I could access the users
Referrer header?

Hi Sebastian,

I think you cannot detect this without JavaScript.
If somebody goes somewhere else, your server is not notified.
You can only try this via JavaScript.

Referer:
And I don't see how the Referer header can help you out.
It is send to the next site (if send at all).

Session:
No go either.
A Session is nothing more than a piece of data on the server that is
linked to a certain visitor via a PHPSESSID (via cookie/url/form).
I don't see how they can help you with this.

So bottomline, bad luck.
You need JavaScript (or some other clientside technology, like an JAVA
applet).

Correct me if I'm wrong, but if user left his site, and then returned
refer would point to the other site. So detecting refer value could
possibly help the problem.
Hi Piotr,

I think you are wrong. ;-)
Or I miss something completely in this discussion.

Please check the answer I wrote to Sebastian for details.
And, of course, feel free to correct me/explain to me how to use the
referer header in a usefull way to detect a user leaving the site. I
still don't see how.

Regards,
Erwin Moller
>
@Sebastian
Refer it's send by the user, so can't be trusted. You can use it
to improve the functionality of the site, but don't use it to any
critical checks (like access controll ect.).

It's also possible, that refer will be empty, when user types in the url
or opens new window in 'new tab' (not sure about that though).

best regards
Piotr N
Jun 2 '08 #14
Erwin Moller wrote:
>>>after the user left the site and
returned.
I think you are wrong. ;-)
Or I miss something completely in this discussion.
Part refer is useful, is the moment when user *returns*.
Not when he's leaving. I believe that Sebastian wants to detect
*returning* clients (so he wont display welcome to them), not leaving ones.

If Sebastian sees that the users was on his site recently (session is
already there), but the refer does not point to his site, then he can
guess, that the user was on a site X and from the site X returned to his
site.

Ofc, you need to assume that session is stored in cookies, users accepts
and keep them, and that he returns by clicking on link.
But as for such trivial thing, as hiding welcome message, you can do so,
without risking it will spoil browsing experience for anyone.

best regards
Piotr N
Jun 2 '08 #15
Piotr schreef:
Erwin Moller wrote:
>>>after the user left the site and
returned.
>I think you are wrong. ;-)
Or I miss something completely in this discussion.

Part refer is useful, is the moment when user *returns*.
Not when he's leaving. I believe that Sebastian wants to detect
*returning* clients (so he wont display welcome to them), not leaving ones.

If Sebastian sees that the users was on his site recently (session is
already there), but the refer does not point to his site, then he can
guess, that the user was on a site X and from the site X returned to his
site.

Ofc, you need to assume that session is stored in cookies, users accepts
and keep them, and that he returns by clicking on link.
But as for such trivial thing, as hiding welcome message, you can do so,
without risking it will spoil browsing experience for anyone.

best regards
Piotr N
Hi Piotr,

All clear, I see now what you ment earlier.
I was focussed on the 'detecting leaving the site' part of the question.

Regards,
Erwin Moller
Jun 2 '08 #16
On 9 May, 12:05, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
Piotr schreef:
Erwin Moller wrote:
>>>after the user left the site and
returned.
I think you are wrong. ;-)
Or I miss something completely in this discussion.
Part refer is useful, is the moment when user *returns*.
Not when he's leaving. I believe that Sebastian wants to detect
*returning* clients (so he wont display welcome to them), not leaving ones.
If Sebastian sees that the users was on his site recently (session is
already there), but the refer does not point to his site, then he can
guess, that the user was on a site X and from the site X returned to his
site.
Ofc, you need to assume that session is stored in cookies, users accepts
and keep them, and that he returns by clicking on link.
But as for such trivial thing, as hiding welcome message, you can do so,
without risking it will spoil browsing experience for anyone.
best regards
Piotr N

Hi Piotr,

All clear, I see now what you ment earlier.
I was focussed on the 'detecting leaving the site' part of the question.

Regards,
Erwin Moller
....but getting back to the original post:
after some testing found that sometimes the
old session data remained even after the user left the site and
returned
Maybe - it depends on your definition of 'left the site'.

Sessions work by getting reaped when they've not been active for a
while (or when you explicitly destroy them in your code). OTOH the
session cookie will be retained for as long as the browser session is
active.

How you go about addressing your problem depends on what you are
trying to achieve:

e.g. if you want to see how users get in your site before abandoning
it, then the best solution might be to write your own session handler
which also logs the current URL then migrate this data to a log when
the session is reaped.

If you merely wish the sessions to expire quicker then adjust the
session.gc_ parameters

C.
Jun 2 '08 #17
I'll need to do some more testing, but just running a quick
preliminary test I found the Referer header never contained anything
*unless* the user was navigating within the site. Could be the
firewall? Anyway, this is just as well - as long as it doesn't point
to our site then I'll display the greeting. Thanks again everyone.

Cheers,
- Sebastian
Jun 2 '08 #18
sebastian wrote:
I'll need to do some more testing, but just running a quick
preliminary test I found the Referer header never contained anything
*unless* the user was navigating within the site. Could be the
firewall? Anyway, this is just as well - as long as it doesn't point
to our site then I'll display the greeting. Thanks again everyone.

Cheers,
- Sebastian
On YOUR system, with your browser and your firewall. Other combinations
work differently.

HTTP_REFERER should NEVER bet trusted.

The bottom line is - whether you want to believe it or not, HTTP is a
stateless protocol. There is no way you can reliably tell if someone
has left and returned to your site.

Others have told you that, also. It's time you to understand it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 2 '08 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: gsb | last post by:
I trying to use sessions to save a user name/id after login. If the user leaves the site and comes back, how do I force a new session and login?
6
by: hb | last post by:
Hi, Would you please tell me how to detect if the client's browser is closed? I need such event to trigger a database modification. Thank you hb
3
by: someone | last post by:
Hi, Is it possible to detect if the user has shut down the window holding my ASP2.0 page and/or if the user goes to another page? For my application I need the user to click on the EXIT button...
8
by: Luke Matuszewski | last post by:
I have read all posts about how to detect that url have changed to new page and trigger the event handler then eg. function aidLogout(evt) { if(evt) { /* maybe via analyse of evt object i can...
2
by: Cam | last post by:
Hi to all I have searched this subject and found some posts but none of them seem to answer my problem. I am developing a shop site and need to detect when a session times out through...
7
by: hiriumi | last post by:
Hello folks, I have a web application that has basic authentication turned on (IIS). What I would like to accomplish is detect whether user is navigating away from the site or simply going to the...
1
by: nebulus | last post by:
I'm working on a web app that under normal circumstances will be happy with the Session_OnEnd event, but when a user leaves a page by closing the browser by either Alt+F4 or just hitting the "X",...
7
by: Baron Samedi | last post by:
I coded up a hit counter, then extended it to see who was reading my blog, by matching IP. The problem is that I am swamped by crawlers. How can I detect a human, or a crawler? If I can handle...
5
by: =?Utf-8?B?QW5keQ==?= | last post by:
As per the question really. Not trying to stop them leaving, but just detect WHEN they leave the site
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.