Help with a link to referring page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
matthines
Forum Newbie
Posts: 4
Joined: Sat Jan 15, 2005 2:28 pm

Help with a link to referring page

Post 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???
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
matthines
Forum Newbie
Posts: 4
Joined: Sat Jan 15, 2005 2:28 pm

Post by matthines »

can someone give me some code or a more detailed explanation of how I can accomplish this?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

search for "breadcrumb"
matthines
Forum Newbie
Posts: 4
Joined: Sat Jan 15, 2005 2:28 pm

Post 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)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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"
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post 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>
matthines
Forum Newbie
Posts: 4
Joined: Sat Jan 15, 2005 2:28 pm

Post 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.
Post Reply