Home php How to make a redirect after performing a php script?

How to make a redirect after performing a php script?

Author

Date

Category

Need for registration system. Those. The user clicks the “Login” button, the script is running in a separate file that processes the data that entered the user (login, password) and then redirect the user back to the main page. But when I insert the Redireche script to the end of the script, I meet with the problem described in my previous question

maybe there are special solutions for this?


Answer 1, Authority 100%

Redirect is made by sending the NTTR header Location: using the Header () function. After sending this header, the Exit statement must be called, since the segment of this header does not stop executing the script. That is, in general, this code

header ("location: /index.php");
exit;

In this particular case, if the input button was pressed, the method will be post – provided that you have in the form it is specified – and if you have done a redirect, then Get .

// in the login processing script (login)
If ($ _Server ['Request_Method'] == 'Post') {
  $ login = $ _post ['login]';
  $ password = $ _post ['password'];
  // here further processing - check, recording in session
  Header ("location: /index.php");
  exit;
}

Answer 2

If you are using ajax query, then in the case of Success, I performed the following:

// instead of $ _server ["script_uri"] indicate the path to the page to which redirect
window.location.href = "& lt;? = $ _ Server [" script_uri "]? & gt;";

Answer 3

Referring to your previous question and this too:

if (isset ($ _ post ['enter'])) {
  $ login = $ _POST ['Login'];
  $ password = $ _post ['password'];
  $ result = mysqli_query ($ Connect, "Select * from Users WHERE LOGIN = '$ LOGIN'");
  $ row = mysqli_fetch_assoc ($ Result);
  if ($ row ['password']! = $ password) {// Not sure login or password}
  ELSE {
     // I asked the session and still
    $ _Session ['user_log_in'] = 1;
      / * 1 means that the user logged in,
       And if you want to `output, then the value when requesting the output must be changed by 0. * /
    EXIT (HEADER ("Location: /Index.php"));
  }
}

I used a separate page to enter. Intended in index.php Code:

if (isset ($ _ get ['login'])) include ('login.php');
ELSE INCLUDE ('iPage.php');

and at the same time in the index file I had little code, and a specific code was recorded in certain files that when requesting Get was inserted into index.php

Therefore, on the same page there may be a cyclic redirect. This is not checked

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