I was guessing that what you were trying to do was create a link back to the previous page (the page that "referred" you to the current page).
isn't reliable for this in general, due to some proxies and some older browsers. But it sounds from your original post as though you're using a CGI to create pages. So I'm unclear on what, exactly, you're trying to do. Are you trying to create a link back to the page from outside of your side that originally referred a session to your site? Or to some static page on your site?