0

My goal is to redirect a user who tries to search for data that is not found in a db, back to the page that has the search form. So the flow is begins in form.php where user enters the id number and he is taken to the page that has the queries on the db processform.php,if there is no results, he/she is to be taken back to the search form. I have used the header function

header("Location: http://".$_SERVER['HTTP_HOST']."/<folder>/so.php");

Unfortunately this is giving the usual error:

Warning: Cannot modify header information - headers already sent by (output started at C\xampp\htdocs\proj\header_n_menu.php

I have also tried the

http_redirect("http://localhost/so.php");

But that gives out this error:

Uncaught Error: Call to undefined function http_redirect() in C:....

Is there any other way you redirect my users to another page automatically?

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 1
    If you're encountering that "headers already sent" message often, then it's time to [understand it](https://stackoverflow.com/a/8028987/476) and change your code so it doesn't happen. – deceze May 08 '20 at 07:22
  • The main fix here is to ensure your redirect code is run before any output is generated. In a regular PHP page, without a framework, this means putting it before the ` ` tag. – halfer May 15 '20 at 10:47

0 Answers0