Page 1 of 1
Help with a link to referring page
Posted: Sat Jan 15, 2005 2:31 pm
by matthines
I am designing a huge site where we will allow people to post products for sale. I need to have a link at the bottom of each page that will take you to the previous page. So, in PHP I am just creating a link to $_SERVER["HTTP_REFERRER"]
However, the problem is, the referring pages have variables on the end of the url that the http_referrer variable does not grab. These variables are critical to distinguishing different pages. An example url is
http://garagesaleslocal.com/view.php?ac ... type=admin
My question is this
How can I get the $_GET variable that are at the end of the URL and add them to my go back link???
Posted: Sat Jan 15, 2005 2:35 pm
by feyd
first off, if back tracking is important.. do not use referrer.. it's not guaranteed to exist.
You can pass the last url via sessions, cookie, or form fairly easy.
Also, have a look through our discussions on "breadcrumb".. some have quite advanced storage..
Posted: Sat Jan 15, 2005 2:45 pm
by matthines
can someone give me some code or a more detailed explanation of how I can accomplish this?
Posted: Sat Jan 15, 2005 3:08 pm
by feyd
search for "breadcrumb"
Posted: Sat Jan 15, 2005 7:52 pm
by matthines
I'm not so sure thats what I want. I checked all the posts when I searched and it seems a bit different. All I really want is a link to the last page the user was on (including the variables on the end of the page url)
Posted: Sat Jan 15, 2005 8:20 pm
by feyd
as I've said, you can use the session as a means to transfer it over from page to page:
Code: Select all
session_start();
$_SESSIONї'last_page'] = $_SERVERї'SCRIPT_NAME'] . (!empty($_SERVERї'QUERY_STRING']) ? '?' . $_SERVERї'QUERY_STRING'] : '');
now, there are some precautions needed, like nowing when and when not to actually run this kind of code. For instance, say you travel to an "add to cart" type page, and the user wants to add more than one to their cart. This page shouldn't store a last_page in the session, or it will lose the ability to "continue shopping"
Posted: Sat Jan 15, 2005 9:16 pm
by magicrobotmonkey
alternativly you can do it in javascript - as long as you handle the cache correctly, it should work:
Code: Select all
<a href="javascript:history.go(-1)">
Go Back
</a>
Posted: Sat Jan 22, 2005 2:07 pm
by matthines
Thanks alot guys. You gave me exactly what I needed. For now, I am just going to use the javascript way because it is so simple. I may, in the future, use the method of passing the query string in a session var. I like that idea...very good thinking.