简体   繁体   中英

Using PHP, how do I determine which page I came from?

First off, I am a PHP noob. That said, I have some PHP code that was given to me which creates a PayPal shopping cart. One of the buttons (Continue Shopping) on the Cart page is supposed to return to the previous Product page (of which there are several such pages) which has the View Cart button.

How do I determine which Product page to return to? Put the page name (ie "productList1.html") in a hidden field?

Regarding possible duplicate: I saw that page, and this comment on that page "The problem with this is that HTTP_REFERER is unreliable at best.", so I decided to ask again since that was asked in 2009, and maybe things have changed since then.

In your php:

/* print the page from you came */
print $_SERVER['HTTP_REFERER'];

But if come from your own page, you can modify the link adding a GET parameter such as ?product_id=123 at the end of link and then in your php:

/* print the product id */
print $_GET['product_id'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM