HTTP_REFERER can't really be trusted, as it's input, and so should be considered tainted. Some browsers don't populate it at all (for security reasons), or selectively populate it (browsers aren't supposed to populate it if they follow a link from HTTPS to HTTP)

I also wouldn't suggest going with a session approach, as the user may spawn multiple windows, and so the last page they visited in that session may not be the last session in that window.

I think a breadcrumb approach is good, and just tell the user to click on it.

or you can do another potentially bad thing, and confuse the hell out of your visitors:

print <<EOF; Content-type: text/html <html><head><title>Go Away!</title></head> <body onload='history.go(-1);'></body></html> EOF

Typically, if I have a page that is going to need to send someone back to where they came from, I'll do like tlm suggested, and send the location they came from in a hidden field (eg, if they trigger a page that needs authentication, I'll pass them to the authentication page, but keep track of where they tried visiting, so that after they authenticate, I can send them back to where they were trying to go)


In reply to Re^2: history.back() by jhourcle
in thread history.back() by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.