I am having a hard time getting $HTTP_REFERER to work. Does anyone have an alternative way of referring back to the previous page?

Here is how I call my header.

header("Location: $HTTP_REFERER");

I get an error message that says the header cant be sent and that it was already sent by my error function. When I remove the error function from the script the script just hangs.

Is there another way to refer back to the referring page?

Greg

    I fixed the problem where I could bnot send headers beacause there was already output. The script still won't redirect me back to the calling page.

      try $_SERVER['HTTP_REFERER']
      and don't forget to die();

        I tried a couple different ways to make this work.

        I tried it with Location: URL, Location: $_SERVER['HTTP_REFERER'] as well as trying to use sessions to refer back to the calling page.

        Is there another way to do this.

        header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . $_SERVER['HTTP_REFERER']);

        Greg

          If it locks up, you probably have a loop, header redirecting over and over again.
          make sure after you call header("location.... that you call die();

            I did call die, but it still does the same thing.

            Greg

              You should be aware that you can't rely on HTTP_REFERER having a sensible value. Is HTTP_REFERER really the page you want? Echo what you're getting instead of redirecting and check that. You might have got yourself into a situation where this page is the one that refers you to this page.

                mail() yourself the value of $_SERVER['HTTP_REFERER'] just before you header() and see what it has in it without having to break the script by dumping pre-header data.

                  Ah, it's already broken, so why worry? 🙂 It's like giving CPR to someone with broken ribs. Hey, so you end up puncturing a lung - what's the worst that could happen?

                  Besides, if it's an infinite redirect loop, you're setting yourself up for infinite mails....

                    I have given up on http_referrer. I am using xtemplate and my entire site runs from one index.php script that calls functions in include files. This might be why http referrer is not working. I got around the problem by either making function calls or by passing variables through the browser.

                    Greg

                      referrer is always index.php, always redirects to index.php, boing! loop for ever...

                        Write a Reply...