I was wondering if there was a way of extracting the page that was last viewed with PHP? It's only for pages where someone has clicked through to the page.
I believe $_SERVER is how they want you to do it. getenv won't be supported for much longer. It has to do with global settings etc. Used to be a security risk but with $_SERVER $_GET etc. is fixed apparently. (Disclaimer: all off the top of my head from research some months back. Do not take this for fact and rely on it.)
So how can this be executed from within the code of the page? I've got a page that processes a form and I want to enable it for the user to be able to click "go back" when a form field is missing. This is in my php if(empty($email)) { echo "<p>You didn't enter an email address, please go back and try again</p>"; } Code (markup): I'd like the go back text to be the link to the referring page (the form) Any help very much appreciated
if(empty($email)) { echo "<p>You didn't enter an email address, "."<a href=".$_SERVER['HTTP_REFERRER'].">please go back</a> and try again</p>"; } Code (markup):
Cheers dude, I dropped an R from REFERRER and it worked fine Now I just gotta figure out how to keep the variables intact on the previous form page so I've used <a href='javascript:history.go(-1)'>please go back</a> Code (markup): to keep it working for now
There is a big problem using HTTP referer with IE ... this function simply do not send the URL ... it works with Mozilla but not with IE ... So if someone have an other idea ... exept using a form .... it will be fun !! Thanks
Welcome to the forums walliioooioiooooo The HTTP Referrer works for me with IE. I don't really know how it couldn't work with 1 browser and not another due to the fact it is a PHP function which is executed on the server. My feelings are, it's your server that is at fault if you have your code laid out nicely.
Two comments: - As already mentioned, it's $_SERVER['HTTP_REFERER'] (It is spelled wrong) - This variable is set by the client software and can be manipulated, don't rely on it for anything important. You can put them in a $_SESSION variable.
No apologies necessary Weirfire, I was only clarifying for archival purposes as I remember all to well when I was starting out and couldn't get it to work until I misspelled it. No worries man Edit: Oh and I didn't mean you misspelled it, referrer is misspelled as referer in php and in the HTTP protocol.
There are sometimes browser objects, toolbars, etc. that block the referrer. It's sent as part of the http request from the client. Another way to do things is to set a cookie with every page visit to the location of the page, but that's blockable too.
isnt refferer unreliable? and cookies be blocked?? use sessions its easy i would do something like -------------------------------------------------------------------- page_1.php -------------------------------------------------------------------- <?php session_start(); //some code $page_name = $_SERVER[PHP_SELF]; $_SESSION['page_name'] = $page_name; //some code ?> ------ Code (markup): -------------------------------------------------------------- -------------------------------------------------------------------- page_2.php -------------------------------------------------------------------- <?php session_start(); //some code $previous_page = $_SESSION['page_name']; //some code ?> --- Code (markup): -----------------------------------------------------------------