Quoting William McKee <[EMAIL PROTECTED]>:

> On Sun, May 02, 2004 at 06:28:38PM -0400, Linda Jen wrote:
> > I have been trying to find a way to get the absolute path for the url
> > returned  in HTTP_REFERER.  The url may referce an alias, virtual host,
> > or simply some subdirectory but will not be defined by DOCUMENTROOT in
> > httpd.conf.  I have looked at faq but found nothing.  Help anyone?
> 
> Hi Linda,
> 
> Check out the pod for CGI.pm. It has several useful methods for
> retrieving the script's url[1].

The problem is that she wants the information about the previous URL (the
referer), not the current URL.  Since that request is long gone, so is all the
information about that request.

For analysing the current URL, you can look at several of the ENV variables that
apache (or any other CGI complient web server) creates for you, like
SCRIPT_NAME, PATH_INFO and such (and like William mentions, CGI.pm can help in
dealing with those variables).  But for the url in the HTTP_REFERER, that
information is long gone.

You may be able to do something with mod_perl, and a custom Handler that runs
just after the TransHandler phase (which is where all the aliasing and rewriting
and such is done) and sets the info you need in an Apache note.  Here is a very
highlevel idea of what may work (note that I would NOT recommend implementing this):

1. in your code that is analysing the HTTP_REFERER header set an apache note
that states that you want to find info about an URL
2. generate a subrequest for the url contained in the REFERER
3. In a custom Handler (for simplicity lets say a Content Handler), check the
status of the apache note to see if this is a real request, or if you just want
to return info about the URL
3a. no note, means just return DECLINED and apache will handle the request as normal
3b. if there is a note, replace the info in the note with the PATH_INFO and
SCRIPT_NAME and any other info about the subrequest that you want.  Then return
OK, so that the request does not continue on
4. back in your original program, look at the apache note to see your info once
the subrequest finishes.


I'll admit that I have just described a very convoluted mechanism for figuring
out the real on disk info of an HTTP_REFERER, but only your webserver really
knows how to parse and translate those URLs, hence you need to get the webserver
to give you the info.  Also, remember that the HTTP_REFERER header can not be
trusted, as it can easily be spoofed, and it could even point to an URL that is
not even on your server.


Now that I have written all that, it may be worthwhile asking what you really
need this information for, and how you plan to use it.  There may very well be
an alternate solution to your problem that doesn't require using the
HTTP_REFERER header.

One last thing, since this topic does not sound like it is related to
CGI::Application (which is what this mailing list is for), can I suggest that a
good place for answers of this type can be found on http://www.perlmonks.org/.

Cheers,

Cees

---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/[EMAIL PROTECTED]/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to