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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

http_referer question

Status
Not open for further replies.

brad1978

Programmer
Feb 13, 2009
30
CA
Hey all,
I'm new to perl/cgi and was wondering how you would go about getting the last 2 visited url's of a user? I thought the http_referer would work but it seems that I can only get the last url. I understand that the http_referer can be spoofed but this is for an intranet and is not accessible by the outside world. Any help or advice would be appreciated.
 
I dont think this is accessible from perl.

Usually you can get to the previous page using javascript and it's 'history' object, but that wont expose the URL.

Perhaps you can set a cookie with previous history in it (if you have any influence over the user's previous pages.

HTH
 
Thanks Jez,
Ya, I need the full URL. I'm building a custom 404 page that captures and writes out the previously visited url into a form field so I can be notified of broken links. I was hoping http_referer would be usable as I would need to modify about 1200 pages to use cookies or sessions to capture that info...
 
Well.... it may be a bit of a long way to do things, but you could always get the user's IP and then grep the server logs with today's date and see what that IP has been calling, perhaps get all calls within the last 10 minutes.

Alternatively you could create some kind of search in the 1200 odd pages for the CURRENT url, i.e. the one that caused the 404. (kind of like a find-in-files which is often a tool in your IDE).

 
Firefox (possibly other browsers, or other Mozilla browsers anyway) has a capability to where JavaScript can request extra privileges, like a Java applet can. Here's one link I dug up on a quick Google search:
Basically if the user permits the JavaScript some extra privileges, then JavaScript will be able to read more of the user's history.

For your purposes though, if you're just using this for a 404 page to report the link they came from, $ENV{HTTP_REFERER} should be enough. Why would you need the other page they were on before the last one? The last page is the one that sent them on a faulty link.

Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
The last page is the one that sent them on a faulty link.

Thats why he wants it, to find the pages with the bad links. There must be an easier way to do this.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Hi

[tt]
[highlight white]+-[ foo ]-------+[/highlight] [highlight white]+-[ bar ]-------+[/highlight] [highlight white]+-[ 404 ]-------+[/highlight]
[highlight white]| |[/highlight] [highlight white]| |[/highlight] [highlight white]| |[/highlight]
[highlight white]| Hi, I am Foo. |[/highlight] [highlight white]| Hi, I am Foo. |[/highlight] [highlight white]| Hi, I am 404. |[/highlight]
[highlight white]| |[/highlight] [highlight white]| |[/highlight] [highlight white]| |[/highlight]
[highlight white]| [blue]link to bar[/blue] [green]---[/green][/highlight][green]->[/green] [highlight white]| [blue]link to doh[/blue] [red]---[/red][/highlight][red]->[/red] [highlight white]| |[/highlight]
[highlight white]| |[/highlight] [highlight white]| |[/highlight] [highlight white]| |[/highlight]
[highlight white]+---------------+[/highlight] [highlight white]+---------------+[/highlight] [highlight white]+---------------+[/highlight]
Request : foo.htm Request : bar.htm Request : doh.htm
Referer : - Referer : foo.htm Referer : bar.htm
[/tt]
In which situation could the link on foo pointing to bar be bad ?

As Kirsle wrote, no reason to suspect other pages than the referrer.

Feherke.
 
Maybe not in a normal web set up, but he said it was on an intranet, so perhaps the more info about the path to a 404 the better or easier to debug the problem.

just my 0.02c

:)
 
logging your visits to a DB, and then query by IP/Session ID would be more efficient than grepping logs.

The previous referer is a quandary to me also ...

Browser's aren't obliged to give up their history, especially if javascript is disabled... I'd be more inclined to resolve this on the server side ...

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top