我有使用GET的搜索功能,就像我搜索'Apple'一樣,它會重定向到這個特定的URL: /search.php?search=Apple
。 現在,如果我在購物車中添加此產品,它會去addtocart.php文件&應該重定向到當前頁面。在addtocart.php文件中,我有這樣的代碼,如果一切順利,它應該去URL: $page?message=Product has been added to your cart
。現在的問題是兩個'?'來自URL,它不會在第一個地方顯示消息&不會顯示包含搜索結果的頁面。 爲了找到當前頁面的URL,我有這個代碼。在URL中傳遞參數以及前面的參數
$page = $_SERVER["REQUEST_URI"];
$page=(stristr($page,"/"));
$_SESSION['page'] = $page;
在addtocart.php文件中,我在購物車中添加產品後,將$ page頁面的值重定向到同一頁面。 所以我這段代碼重定向:
header ("Location: $page?message=Product added to your cart");
所以最終的URL,它重定向到看起來像:search.php?search=apple?message=Product added to your cart
。而且它實際上並沒有通過參數&,因此不能進行搜索。我錯過了什麼,你可以幫忙嗎?
感謝哥們,它工作得很好。 –
你能再告訴我一件事嗎?假設我有這個網址:www.example.com/veg.php?sub_cat=33&message=Productaddedtoyourcart。我怎樣才能得到這個網址:/veg.php?sub_cat=32?這是因爲下次如果某個人試圖再次添加同一產品,則會向他發出警告,並且因爲網址www.example.com/veg.php?sub_cat=33&message=Productaddedto yourcart&message = ProductAlreadyExists。所以最終它會打印兩次。 –
你可以通過'$ _SERVER ['REQUEST_URI']'得到'veg.php?sub_cat = 33&message = Productaddedtoyourcart&message = Produc tAlreadyExists'字符串。 – atxpunkrock