Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Get referring page before variables added



8:49 pm on Jan 18, 2013 (gmt 0)

10+ Year Member

I want to try to store the referring page so that I can access it even if I reload the current page with a new variable and I'm just stumped.

For example, if I go from catalog.php?&category=10 to catalog.php?product=25, I want to be able to go back to catalog.php?category=10 even if I add variables onto the product part (ie, catalog.php?product=25&a=like). In the latter case, when I go back, it will return me to the product listing again, not the original category listing.

Any help would be appreciated.


7:10 am on Jan 19, 2013 (gmt 0)

WebmasterWorld Senior Member swa66 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Sounds like you want to control where the back button in the browser goes to ?

That's commonly considered breaking the back button and should not be done.
I don't think you can do it on the server side of things, you can using client side scripts (javascript) AFAIK -more complex use of ajax sometimes needs to do this to keep the back button working properly.

What you can do relatively easy is to store server side for the given session what the user has been doing and keep a "state" for them, that should solve your need without changing the URLs.


8:41 am on Jan 19, 2013 (gmt 0)

10+ Year Member

I'd love to see an example of how to keep and recall a specific url "state", it's been vexing me since yesterday.

The long and skinny of it is my company just launched a small retail end to our business with our entire product catalog sitting in a mysql database plugged into a public facing front end. I've built a tablet based interface, purely for people to search the catalog while in the showroom, so it's not like Joe Public is going to be using it - it literally sits on our counter in front of me and is secured away from prying eyes outside our network.

Having said that, the end user will never see the browser back/forward buttons because the tablet display is locked in full screen all the time, we got them purely for this. I tried history.go(-1), but when someone "likes" something or "adds to cart", it refreshes and adds a variable to the query string rendering a history(-1) not only useless, but downright nasty without the right checks in place. I'm not well versed in AJAX so I need a page refresh to make these functions happen.

So therein lies the crux of my issue. I need to be able to say something like:

if ( (!isset($add)) || (!isset($liked)) ) {
$referrer = HTTP_REFERER;
} else {
$referrer = $_SESSION['saved_referrer'];

...but I can't wrap my head around the syntax and how to make it all remember specific history items (and recall said items for that matter). Any further help or advice would be awesome. Sorry for being verbose, it's a weird issue to try to explain.


10:25 am on Jan 19, 2013 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

HTTP is "stateless".

You'll need to either use a cookie to store what you want, or pass it as a parameter.


12:04 pm on Jan 19, 2013 (gmt 0)

WebmasterWorld Senior Member swa66 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

I'd start reading up on sessions

Ref: [php.net...]


3:12 pm on Jan 19, 2013 (gmt 0)

10+ Year Member

I'm not too bad with sessions, most of the site relies on them to function as is, but storing visited url's has been eluding me for some reason. Worst case scenario, I'll rewrite the url on each page and store that but I was hoping there was a simpler or more elegant solution. Thanks anyway guys.

Featured Threads

Hot Threads This Week

Hot Threads This Month