We help IT Professionals succeed at work.

Check out this week's podcast, "Dairy Farms to Databases: Community's Hand in Technology"Listen Now


Who is pointing to me?

manchung asked
Last Modified: 2006-11-17
I got a pretty popular webpage called "myweb.html". Many webpages out there must have a link to my page. Now, I am being curious about who is pointing to my page.

To figure that out, an intuitive way is to use HTTP_REFERRER. But how? I don't want to move "myweb.html" to "someprog.cgi" or "server_side_include.shtml" because it's a tough job to ask those people currently pointing to "myweb.html" to update their links. Not to mention I don't even know what they are and where they are in the first place.

That's why I came up with a way that might help:

out_there.html -(1)--> myweb.html -(2)--> myweb2.shtml

(1): When people follow a link to myweb.html from some web page out there,...

(2): I want to automatically redirect them to "myweb2.shtml" where I can hopefully capture the HTTP_REFERRER using server side include. A lame way to redirect them is to use
<meta http-equiv=refresh content="1; ...>,
but HTTP_REFERRER is gone when it gets to myweb2.shtml.

P.S. server side include only gets executed when the files end with "shtml".

Can anybody tell me how I can figure out who is pointing to me?

Thanks in advance.
Watch Question


Edited text of question
Most Valuable Expert 2014
Top Expert 2015

Is your server set up with a RefererLog?


Even if my server is set up with a ReferrerLog, I don't have access to it because the log directory is set to 700 and I am not root.

Trying to locate all the links to your site is probably futile and by changing the name of your page, you'd create even more broken links on the web! I like your idea of keeping the page name as much as I hate broken links ;-)

I don't think you can "preserve" the old referrer, but you can use JavaScript to do what you want to do.
---- quoted from JavaScript guide ----
When a user navigates to a destination document by clicking a Link object on a source document, the referrer property contains the URL of the source document.
Evaluate the referrer property from the destination document.

If the user clicked on a link to get to the current URL, referrer contains the URL the user linked from. referrer is empty if the user typed a URL in the Location box, or used some other means to get to the current URL. referrer is also empty if the server does not provide environment variable information.

referrer is a read-only property.
---- end quote ----

There are several ways to use this property. I'll just give you two:
* From Myweb.html, you can redirect to the next page by using location="myweb2.cgi?ref="+document.referrer; (don't forget a message for poor people without JavaScript ;-) That program delivers your next page and saves the ref-parameter to a file.
* Without redirecting,  you can call a CGI-program in myweb.html by a) including an image that is generated by CGI or b) calling location="somecgi.cgi?ref="+document.referrer; where somecgi returns the "no content" status code (204) that does not change your document.
* If you'd like to rename your page eventually, combine the two by automatically redirecting to "newpage.cgi?ref="+document.referrer and placing a link in the old document like: Page has moved to newpage, please update your bookmarks. If your browser does not support JavaScript-redirects, please <a href="newpage.cgi?ref=unknown">click here</a>to go to the new page.

I don't think there is a solution without scripts - as you can neither use CGI nor SSI in your page, JavaScript is the only solution.
Let me know if that helps ;-)
I agree with Holger, I implemented the document.referrer trick on a page some time ago.
You might alternatively want to set a cookie with the value of document.referrer, but then most people would see that you are setting a cookie. :-(


Thanks, Holger and Christian, for your ideas. Actually, I thought of using javascript also. But, it doesn't work for people using old browsers or those who turned off javascript/java.

I also tried turning myweb.html into some symbolic link to myweb2.shtml on UNIX. Although myweb2.shtml was loaded, the server side include code didn't get executed.

I know it's hard to find a perfect method to retrieve the HTTP_REFERRER this way. Is there a way out there that works in most cases?

Thanks again.


Write a new file you want and then in myweb.html write something like this page have moved to a new location pleas eupdate your bookmarks.



I did that. It didn't work because, maybe, they were too lazy to update their links.

Can you set up myweb.html to be CGI and be executed?

Or if you want you can tell me your page address or your provider and I can go look for solutions.



CGI programs must end with ".cgi". So, CGI code saved in files with extension html is never gonna get executed.

About my ISP, it's my college. They won't change the configurations of the webserver for me because of security issues.
I hereby reserve the (c) for this answer, but I won't have time to test it before tomorrow: What I do on one of my pages to see who has looked at it is:
<a href="mailto:mymail@somewhere.com"><img src="XSlog.pl"></a>
*ggg* - kind of sneaky, but this will call a Perl-Script that does not only return the image (simply the image header and then output the file), but also logs date, time, IP and domain of the "visitor" to a file. It should also be able to save the referrer. This is not a server-side include, it simply requests the file from the server --- I don't know which value the "http-referrer" has in this case (i.e. the page requesting the image or the "original" referrer)... might/should work though.

P.S.: As a JavaScript-Expert I would like to remark that JS IS a way that works in most cases!! *g* For best results, you could do a combination of the methods by enclosing THIS solution in <noscript>-tags ;-)



I tried it before. The http_referrer would be "myweb.html" because "myweb.html" refers to "XSlog.pl".

Thanks for your contributions.

Well... as long as nobody offers a better solution, I'd like to "refresh" and modify my first suggestion:

You "cannot" change the name of your main page, so everybody who enters will enter via that page. As soon as you leave it, the HTTP_referrer will contain the URL of your first page => therefore, you have to capture the referrer on the first page. It seems like you can't use either CGI or SSI - as I said before, I think JavaScript is the solution that will give you the best results, it might even be the only one. It's definitely better than nothing and you will soon find out how many people have it / don't have it.
A solution that annoys the lowest number of visitors could also be this:
* include a META REFRESH in the head section that forwards to "newpage.cgi?ref=unknown" after 5 seconds
* include JS-code that beats META to it and forwards to "newpage.cgi?ref="+document.referrer after 1 second.
* include a text message and a link to "...?ref=noMETA" in the document for impatient people and if something goes wrong somewhere...

If you really want to find out badly who might point to your site, you could have your script generate an extra-line if an unknown referrer is passed in. Something like: "I have moved my site. You could do me a great favor by telling me who still has obsolete links to my old URL: [________] [ Submit ]".
I know that's not exactly what you're looking for, but all methods combined should help you find almost everything.

P.S.: I really don't know so much about UNIX (just working knowledge) - but if you could turn myweb.html into a link that loads myweb2.shtml, why can't you turn it into a link that loads myweb2.cgi? Even without any parameters and without SSI, the script would have access to HTTP_referrer...

Good Luck and let me know if you like one of these solutions enough to take it as an answer ;-)



 I think your suggestion is the best "work around" for my problem. About the symbolic link I mentioned, although myweb2.shtml seemed to be loaded, the server-side include code didn't get executed -- I was still unable to capture the HTTP_REFERRERER.

 I already have a cgi program at hand that takes the referrer as an arguement and processes it. Can you give me the corresponding JAVASCRIPT code that forwards people to my new page?

 If you don't mind, I will take your suggestions as an answer and I will give you a B.

  Thanks again.

This one is on us!
(Get your first solution completely free - no credit card required)


I tried your suggestion. It worked.

Glad I could be of help.

ok, people.... I'm really almost always a "nice guy", but I have to tell you that I am not exactly thrilled about this turn of events - not so much for the points as for general "netiquette"...

1] I proposed a better solution than this in my very first comment. Your complaint was that it wouldn't work without JavaScript and that's what all my following comments were about!
2] My last solution offered a combination of 3 strategies that give you decent results even without JavaScript.
3] You had already agreed to accept my "answer" - I'd understand it if somebody had posted an alternative solution that does everything you want, but this one does less than what I proposed!
4] My solution would have been "almost invisible" to your visitors - this one isn't.
5] A solution doing the exact same thing that this one does only has to take one line of JS-code and one line of HTML-Code!!
6] Having posted an almost complete solution, I feel that this is a "Reject" for which I don't really see a good reason!!
7] You accepted fast enough so I had to "pay" to see which solution was posted!

This really takes me back to locking questions as soon as I know I can answer them! I left it open for somebody to post a "non-JavaScript" solution that might be able to preserve the HTTP-REFERRER, not for a shortened version of my comments!

P.S.: The only results you will ever get for browser are NN, IE and possibly AOL-browser... why pass it in anyway? HTTP_USER_AGENT should do it...

still: no (very) hard feelings, I just wanted to point that out and refer you to the "Expert grading help"...



Actually, I was waiting for your answer yesterday. But, Trevor jumped in before you did and he offered me an answer, not a comment. I didn't really know what to do. I coundn't give him an F.

To be fair to you, I came up a "work around". I think, i still have 20 points left in my account. I can post a similar question. You thenrespond with a simple answer and you get an A.

Sorry again.
Look Holger, I just gave the answer that was required plus a little extra.  Browser was never a requirement of the original so why critize it?

It actually returns many browsers:-

IE 2.0
IE 3.0
IE 4.0
NN 2.0
NN 3.0
NN 4.0
AOL 3.0
AT&T WorldNet Service3.0C-WorldNet

Plus it also returns the platform that the user is on.

Your first comment mentioned using JavaScript but did not actually give any examples, so I hardly posted your comment.  As for netiquette, I hardly think a flame is netiquette do you ;-)

Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.