php重定向标头不是通过ajax调用发送的

i am trying to send header from a php file that is called with ajax. problem is, when i validate all information with php, i want to redirect to another page but headers dont work! any ideas?

what the code does:

//------------- index.php
on click of input, function passes <input> values through $_POST to login.php
if($_SESSION[superman]==true){redirects to index_main.php}

//------------- login.php
all it does is validate forms and if login and password are correct, it sets $_SESSION [superman]=true

The redirect will only redirect the Ajax call! If you want to change the displayed page in the browser, you'll need to redirect using Javascript once the Ajax call completes.

  • Make your Ajax call return a value indicating successful login (for example the string true or maybe the URL to the page you want to load)
  • Check the return value of the Ajax call. If success, change location.href using Javascript.