Home php Header ('Location: index.php'); Does not work how to fix?

Header (‘Location: index.php’); Does not work how to fix? [Duplicate]

Author

Date

Category

Header ('Location: index.php'); not working.
(Sending all field shape fields using AJAX jQuery).
How to fix?
If there is a mistake when filling, then normally works


And if success happens like this:

How can I do normally? Thanks in advance!

HTML Code:

& lt; form method = "post" id = "form" action = "javascript: void (null);" ONSUBMIT = "CALL ()" & GT;
   Login
   & lt; Input Type = "text" name = "username" / & gt;
   Password
   & lt; Input Type = "Password" name = "password" / & gt;
   & lt; Button Type = "submit" name = "submit" & gt; Login & lt; / Button & gt;
& lt; / form & gt;
& lt; div id = "results" & gt; output & lt; / div & gt;

js code:

function call () {
  VAR MSG = $ ('# Form'). Serialize ();
  $.ajax ({
    Type: 'Post',
    URL: 'login.php',
    Data: MSG,
    SUCCESS: FUNCTION (DATA) {
      $ ('# Result'). HTML (DATA);
    },
    ERROR: FUNCTION (XHR, STR) {
      Alert ('An error occurred:' + xhr.responsecode);
    }
  });
}

php code:

& lt;? php
include 'core / init.php';
If (empty ($ _ post) === FALSE) {
  $ username = $ _post ['username'];
  $ password = $ _post ['password'];
  If (Empty ($ UserName) === True || Empty ($ password) === True) {
    $ errors [] = 'You must enter the username and password.';
  } ELSE If (User_exists ($ UserName) === False) {
    $ errors [] = 'We can't find that the username. Have you registered? ';
  } ELSE If (User_Active ($ UserName) === False) {
    $ errors [] = 'You have not yet activated your account!';
  } else {
    $ login = login ($ username, $ password);
    if ($ login === FALSE) {
      $ errors [] = 'This combination of the username or password is incorrect.';
    } else {
      $ _Session ['user_id'] = $ login;
      Header ('Location: index.php');
      exit ();
    }
  }
}
Echo Output_errors ($ errors);
? & gt;

Answer 1, Authority 100%

Replace

Header ('Location: index.php');

on

exit ("& lt; meta http-equiv = 'refresh' content = '0; url = /index.php'> ; ");

Answer 2, Authority 200%

Header ('location: /index.php');

nothing should throw anything in stdout, otherwise some browsers (Khe-Donkey-Khe) may think that the title is erroneous.

for light reading.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions