Page 1 of 1

Sending Visitors Back to Referring Page on Pressing a Button

Posted: Thu Sep 25, 2008 5:43 pm
by anointing
Hi,

I'm new to php and am currently developing a php shopping cart. I've created a page for shoppers to check the status of their cart and have already implemented the functionality for
displaying the cart for when it is empty and also when it has an item.

I now want to add an additional functionality for when the cart is empty whereby a button will appear offering shoppers the option to continue shopping: on pressing the button, they would then be directed back to the referring page. I'm already familiar with header("Location: goto.html").

What I would like to know is the code to implement the extra functionality mentioned above
that is triggered when the button is pressed.

I would really appreciate your help on this guys.

Re: Sending Visitors Back to Referring Page on Pressing a Button

Posted: Thu Sep 25, 2008 5:49 pm
by LuckyShot
Hi anointing,

Have you tried

Code: Select all

<?=$HTTP_REFERRER?>
?

Cheers

Re: Sending Visitors Back to Referring Page on Pressing a Button

Posted: Fri Sep 26, 2008 1:47 am
by VladSun
I would not count on HTTP_REFERER because it's a user data (e.g. some browsers will not send it).
Instead, in every page save the page url in a session variable. This way you'll have "the previous" page URL available.

Re: Sending Visitors Back to Referring Page on Pressing a Button

Posted: Fri Sep 26, 2008 2:48 am
by The_Anomaly
Perhaps every link to the shopping cart could have a URL variable "referrer" that has the name of the page, and with that, the shopping cart's "Go back" link would be populated.

Re: Sending Visitors Back to Referring Page on Pressing a Button

Posted: Fri Sep 26, 2008 8:43 am
by anointing
Hi

In view of continuing browser inconsistencies in retrieving the referral URL, I've decided to use javascript to point shoppers to the home page when they press the "Continue Shopping" button. This is pretty much the same as redirecting them back to actual referring pages because with good navigation throughout the site, they can readily move around anyway.

The site is still under construction; here's the php code snippet and it works:

echo "<input name='Submit' type='submit' value='CONTINUE SHOPPING' onclick='javascript:window.location=\"go_to_homepage.html\"' />";

Thanks for your help

Re: Sending Visitors Back to Referring Page on Pressing a Button

Posted: Fri Sep 26, 2008 8:52 am
by The_Anomaly
anointing wrote:Hi

In view of continuing browser inconsistencies in retrieving the referral URL, I've decided to use javascript to point shoppers to the home page when they press the "Continue Shopping" button. This is pretty much the same as redirecting them back to actual referring pages because with good navigation throughout the site, they can readily move around anyway.

The site is still under construction; here's the php code snippet and it works:

echo "<input name='Submit' type='submit' value='CONTINUE SHOPPING' onclick='javascript:window.location=\"go_to_homepage.html\"' />";

Thanks for your help
I assume you know that a good portion of users will block javascript, which would render your button useless. Heck, No-Script is probably the most popular Firefox add-on I've heard of.