I admit that *I* don't have a very clear understanding of how
web apps work, so the following is likely to be completely wrong.
I'd be interested in knowing what's wrong about it.
Perl generally runs on the server side, and therefore doesn't
have access to the browser's (client's) internal information (in
this case, the contents of the address bar). Javascript generally
runs on the client side: the browser downloads Javascript code and
executes it locally. Have I got that right so far?
Would it be possible for some Javascript code, running in the
browser, to query the contents of the address bar and then send
that information to code running on the server?
My first thought is that this could open up serious security holes,
and that there are measures already in place to prevent it, but I
don't know the details.
By the time the javascript code has been downloaded by the browser,
the url will have changed!
That is, the user starts out viewing page A, and the url for A is in
his browser's address bar.
Page A has a link to the CGI script, B.
The user clicks on the link.
The new page (with javascript in it) comes back to the browser. But
the browser's address bar now shows the url for B.
The url of the prior page (A) may not be accessible to the JS Script,
because browsers often limit what scripts can see for security
purposes.
Thus, the JavaScript only knows that the address bar *now* is B. Even
then, it might not know that, if the script has been filtered so that
it doesn't see the real variables. For example, normally a page's
location is available in via the javascript variable location.href,
but location might be replaced with a different object, whose .href
field contains a different url. With a good quality web anonymizer,
this might be done to improve transparency. Of course, they might
take the easy way out, and strip out any javascript entirely!
The client side javascript script can activate the browser's "back"
functionality (using history.back(), or history.go(-1)), but often
(for reasons mentioned above) won't see anything in the
history.previous field.
Similarly, if the browser hasn't sent the url of A to the web server,
then the server won't pass A's url in via the HTTP_REFERER environment
variable. For that matter, if the user is using an anonymiser, you
can be absolutely positive that it won't send in url A as the referrer
-- it might send nothing, or might make up some random garbage. You
also won't get a referrer if url A was an https page. You also won't
get a referrer if your page was typed into the url bar of the browser
directly. You also won't get a referrer if your page was bookmarked,
and accessed via that bookmark. You also won't get a referrer if
someone made your page their browser's home page, and they clicked
home. You also won't get a referrer if your page is accessed by a web
crawler. Etc, etc,.
Hardly any of this has anything to do with Perl, of course.