Forum Moderators: coopster

Message Too Old, No Replies

Did the user refresh?

         

patriko

6:14 pm on May 17, 2006 (gmt 0)

10+ Year Member



Hey everyone. I figured I'd put this into the PHP section because the outcome of the issue will have to deal with PHP anyway. I wanted to see if there was some server variable, or anything, that could tell me whether or not the user navigated to the page via a refresh or by hitting enter in the address bar. Any ideas?

jatar_k

4:55 pm on May 18, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



not in php really

if someone has no referrer then they may have typed it in to the location bar but browsers don't always give you a referrer so it may just be that you don't have access to it.

for a refresh, I don't know if it would show itself as the referrer, I don't believe it does but you would have to test it out. I don't think it would but who knows.

the var you want to play around with would be $_SERVER['HTTP_REFERER']

you may have more options with a javascript solution

patriko

12:58 pm on May 19, 2006 (gmt 0)

10+ Year Member



Yeah, javascript would work as well. Even with javascript I'll be able to mix in some PHP ... I'm messing around with $_SERVER['REFERER'] now, would using javascript's history variables help the situation any?

patriko

1:43 pm on May 19, 2006 (gmt 0)

10+ Year Member



Okay, using javascript (instead of the PHP I was hoping for), I found out that using the document object, you can find the referrer. The value of document.referrer can tell you more than I thought ... if they refreshed, or clicked onto the page from anywhere else, then naturally the referrer will be the page they came from. However, if they type in the URL and hit enter (a'la the address bar at the top), document.referrer will be blank.

ergophobe

4:52 pm on May 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



When I reload a page, I'm basically just sending the same request and asking the browser to ignore what's in the cache. At least with Firefox if I go to a page and reload, the referrer is the same in both cases (the original referrer). I'm just doing this with the HTTPLiveHeaders extension, so I can't test it in IE, but I would expect it just to resend the original request, referrer and all.

So forget using referrer. How about this :

- you can grab the user's IP ($_SERVER['REMOTE_ADDR']) and then see if the last page requested is the same as the current page.

- you can create a session variable and see if the last page requested was the same as the current page.

In both of these cases, you would get a "hit" for a user who is on the home page and hits a link to the home page, for example. You could use Javascript to catch the onClick and add a URL flag if someone came from your site.

If you were WebmasterWorld and have a lot of users who check the site quickly at the end of the day and right after turning on their computers (oh yes, you know who you are), you would also get a lot of "hits" that may not rerpesent what you want.

In the first case, you would also get a "hit" if two users were surfing from the same IP (as in a home network situation - "Hey Bob, look at this").