-5

How do I redirect to index.php after the correct username and password are submitted in the form.

ADyson
  • 57,178
  • 14
  • 51
  • 63
  • Use AJAX to verify the password, then use `window.location = "index.php";` – Barmar Sep 20 '19 at 15:50
  • Or just submit the form without Ajax and set a Location header on the server (in the PHP script which processes the login request) if the credentials are correct. This will cause the browser to redirect when it receives the header in the response. You can Google more about this very easily – ADyson Sep 20 '19 at 16:01
  • Possible duplicate of [How do I make a redirect in PHP?](https://stackoverflow.com/questions/768431/how-do-i-make-a-redirect-in-php) – Lucas Arbex Sep 20 '19 at 16:29

1 Answers1

1

Here are some links that I saved for my own reference that should help you. Forgive me if you already know much of the information in these answers - the hope is that within the answers/examples there are some important bits that will help.

Login into a website and get html from a page

How to create an admin page to add/remove elements to a drop-down list?

Restrict access to private images

Basically, there are two possibilities.

If you are using a non-ajax form that is processed by a back-end file, you just need to output a redirect to the other page. In PHP, just:

header('Location: new_page.php');

If you are using AJAX (which sends the user-inputted name/pword data to a back-end file that checks them and returns a response), then you get the succeed/fail info in your ajax .done() function -- ie. in JavaScript. In that case:

.done(function(recd){
    if (recd == 'yes'){
         window.location.href = 'http://example.com/new_file.html';
    }
});
halfer
  • 19,824
  • 17
  • 99
  • 186
crashwap
  • 2,846
  • 3
  • 28
  • 62