0

So basically I have siteground hosting my website, and wordpress for building the website. On the home page of the website I have a php code snippet plugin that lets me put php code. The php code there is a typical html form with a input of type select, which lets you choose a product from a dropdown menu. After choosing and clicking the submit button, the forms action is a filterReceive.php file in the root directory of the website.

Once the form submits to filterReceive.php, I have code that takes in the product that the user chose from the dropdown list, and according to the product i want it to redirect the user to that products page.

Below is my code for redirecting the user to the page:

<?php
if (isset($_REQUEST["submit-button"])){


   $product = $_GET['product'];
   if($product == "fridge"){
       echo "entered function";//this text shows up when the filterReceive.php  loads up, so the header function below should also execute
       header ("Location: https://www.ebay.com/");//this header function dosent execute no matter what, even if i use relative file in the directory
        exit();
   }

}
?>

Any help would be greatly appreciated, Im just trying to build simple php code that would redirect a customer to the correct product page after they selected the product from the drop down list and clicked submit. If there are any similar ideas or plugins for wordpress done elsewhere, a link would be super helpful. Thank you all very much!

  • 3
    Remove the `echo` part and it will redirect-- Seems you have turned off your error reporting! Otherwise you would see the warning – B001ᛦ May 12 '20 at 12:42
  • Does this answer your question? [How to fix "Headers already sent" error in PHP](https://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) – Ray May 12 '20 at 13:58

1 Answers1

0

there is a better way to redirect url than header i recommended to use this which i always use in my projects as show:

echo'<script> location.replace("index.php"); </script>';
  • OP is clearly asking for a solution using `php`. Please explain "Why is this a better way" – B001ᛦ May 12 '20 at 14:25
  • For nothing just because when i use header i always get an error so i change it as i told you . – zain al-abdeen May 12 '20 at 14:45
  • So this is better just because you use it? Please take care of the quality of your answers in the future. – B001ᛦ May 12 '20 at 16:33
  • I'm sorry for everything , and i already said that when i use header i always get errors especially with complex functions ,so i use my answer instead , not just because i use it – zain al-abdeen May 12 '20 at 16:38
  • @zainal-abdeen thank you, it solved my issue. When it redirects, it happens slowly, from your experience how can i speed this up? – Wathik Ahmed May 15 '20 at 10:27