Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to detect which page loaded a script? Not talking about referer.

I have a .shtml sliced page and in one of the side includes I have a script that I want to see where the person loaded it from. For example, if they were on the contact page it'd look like http://www.page.com/contact.html.

Right now I am using the HTTP_REFERER and it does half work. If they come directly to a page that loads this script, there is no referer. The user has to actually click an internal link before they are given one. But at this point, it no longer shows what page they are on but instead what page they were on a second ago.

Any ideas or suggestions?

Replies are listed 'Best First'.
Re: How to detect which page loaded script
by phaylon (Curate) on Dec 07, 2005 at 16:38 UTC
    HTTP is stateless. A very unclean option would be to store the last page in a session, but that's really very unclean. If you could tell what functionality you want to gain with this, maybe someone knows a better solution to your problem.

    Ordinary morality is for ordinary people. -- Aleister Crowley
      Someone told me JS could do this, unfortunately I don't know how to pass the information.

      They said window.location would hold the URL. Anyone know how to get a javascript to pass this to my script?

        You still haven't said what you're up to. There may be possibilities with javascript, but what if it's disabled/not working/faked?

        Ordinary morality is for ordinary people. -- Aleister Crowley
Re: How to detect which page loaded script
by kulls (Hermit) on Dec 08, 2005 at 04:11 UTC
    hi,
    you must pass the page name as a hidden value when u click that page.In the receiving end you can get the page name and process it.If they change the page name (suppose u r hardcoding it) from 'contact' to something else, then it's hard to follow up.so better keeptrack the page name, if you want.
    -kulls
Re: How to detect which page loaded script
by PodMaster (Abbot) on Dec 08, 2005 at 09:20 UTC
    Right now I am using the HTTP_REFERER and it does half work...
    Did you check the rest of %ENV? The information you're looking for is communicated via enviromental variables, and if your server is doing its job, it will be in %ENV (If your server is apache, you can find documentation here).

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.