Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie: How do I detect wrong referrer on my page?

Status
Not open for further replies.

JCHallgren

Technical User
Dec 17, 2004
47
0
0
US
I have a simple site that uses a main "index.html" and sub-pages of "showTC.html". How would I detect that someone began viewing site at any page other than main index?

(Some folks have bookmarked the showTC.html page).

I would like to give them some sort of msg (maybe a error box?) to ask them to change bookmark (and optionally put them on index).

Most who visit use on the website name but i suspect some have bookmarked the actual "index.html" page name also.
THANKS!

I did search this forum before posting but found no matches.
 
Since someone could go to any page on the site from any other page, you'd have to have a list of all the pages and check to make sure that the previous page was on the site. The only page you wouldn't have that would be the main page.

Or you could set a cookie on the main page that would expire in half an hour or so, and check for that cookie on every other page. If the cookie didn't exist, then the person hadn't come from the main page.

Using the referrer has a flaw in it in the fact that if someone is on the main page and types in the URL for one of your other pages, then there is no referrer. I don't know if this would be true if they used a right-click and opened a link in another window or not. I use that technique all the time to keep track of my origin while searching for something. Setting and using a cookie would overcome that problem.

Lee
 
>>then there is no referrer

exactly.

so when the page has a referer and its main.html then the page can be viewed, otherwise it will simply redirect back...

Known is handfull, Unknown is worldfull
 
But if you type in the name of another page when you're legitimately on the site, having come through the main page, it'll still redirect back to the main page. If you want to force someone to only navigate the site by clicking on the links, which is what most people probably do anyway, then using the referrer would work fine.

Lee
 
i think thats what JCHallgren wants...

Known is handfull, Unknown is worldfull
 
The first question was:

How would I detect that someone began viewing site at any page other than main index?

Using the referrer only shows what the page where you clicked the link to get to the current page was. Like I wrote, many times I right click on a link in navigating a site so I have the original list of links still open. Using a cookie that expires would be a more foolproof way to do that. I did develop a system for someone a couple years ago to check the referrer to make sure the previous page was on the site, or the main page, and it redirected to the main page if the referrer wasn't in the array of links.

Of course, if someone has Javascript turned off, none of this works, and you'll have to use something server-side to detect what the referrer is.

Lee
 
THANKS for the replies thus far! Ok...based on that...given that I really doubt anyone is typing in actual URL to sub-pages (other than me!), that issue should not be a problem...
Also, the majority of my users (I think) have JS on...and there is no logical reason (that I see) to right-click on link to sub-page...as i can't think of a place where that link would be (other than my site)...so as long as referrer to sub-page contains my site name in it, I'm ok...but...
What if they left my sub-page via a link on it and then returned?
Would that be another reason for cookie use?
 
Using the back button will usually (not sure if it always does) keep the same referrer. Cookies are a little more foolproof, and will allow someone to type in the other page(s) manually. If you're not concerned about that or other possible exceptions, then just checking the referrer will work fine.

Without Javasctript on, none of the things discussed here that operate client side will work.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top