Sending Visitors Back to Referring Page on Pressing a Button

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
anointing
Forum Newbie
Posts: 8
Joined: Wed Jun 18, 2008 10:01 am

Sending Visitors Back to Referring Page on Pressing a Button

Post 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.
User avatar
LuckyShot
Forum Newbie
Posts: 13
Joined: Thu Sep 25, 2008 5:02 pm
Location: Barcelona

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

Post by LuckyShot »

Hi anointing,

Have you tried

Code: Select all

<?=$HTTP_REFERRER?>
?

Cheers
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

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

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
The_Anomaly
Forum Contributor
Posts: 196
Joined: Fri Aug 08, 2008 4:56 pm
Location: Tirana, Albania

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

Post 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.
anointing
Forum Newbie
Posts: 8
Joined: Wed Jun 18, 2008 10:01 am

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

Post 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
User avatar
The_Anomaly
Forum Contributor
Posts: 196
Joined: Fri Aug 08, 2008 4:56 pm
Location: Tirana, Albania

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

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