成功登录后重定向到新页面

Kao*_*aos 6 html php forms login

我确定之前已经问过这个问题,但我已经彻底搜索了答案,但无济于事.(我见过的唯一答案涉及ajax)但我只使用javascript,PHP和HTML.

我有一个login.php页面,我已经创建了一个HTML页面,该页面在用户成功登录后立即成为登录页面.我该如何解决这个问题?

以下是我登录后的登录页面和登录页面的代码transfer.html:

的login.php

  <div id="content">
     <h3>Login to Internet Banking</h3>
     <form id="login" action="" method="post">
        <p>
          <label for="userid">UserID:</label>
          <input type="text" name="UserID" id="UserID"/>
        </p>
        <p>
          <label for="PIN">PIN:</label>
          <input type="password" name="PIN" id="PIN" />
        </p>

        <p>
          <input type="submit" name="btnSend" value="Login" class="submit_button" />

        </p>
      </form>
      <td>&nbsp;</td>
 <p>
        Not yet registered?
 <a href="registration.php">Click here to register</a>
 </p>

  <div id="wrap">
        <!-- start PHP code -->
        <?php

            mysql_connect("localhost", "root", "") or die(mysql_error()); // Connect to database server(localhost) with UserID and PIN.
            mysql_select_db("registrations") or die(mysql_error()); // Select registration database.

            if(isset($_POST['name']) && !empty($_POST['name']) AND isset($_POST['PIN']) && !empty($_POST['PIN'])){
                $UserID = mysql_escape_string($_POST['name']);
                $PIN = mysql_escape_string(md5($_POST['PIN']));

                $search = mysql_query("SELECT UserID, PIN, active FROM users WHERE UserID='".$UserID."' AND PIN='".$PIN."' AND active='1'") or die(mysql_error()); 
                $match  = mysql_num_rows($search);

                if($match > 0){
                    $msg = 'Login Complete! Thanks';
                }else{
                    $msg = 'Login Failed!<br /> Please make sure that you enter the correct details and that you have activated your account.';
                }
            }


        ?>
        <!-- stop PHP Code -->
        <?php 
            if(isset($msg)){ // Check if $msg is not empty
                echo '<div class="statusmsg">'.$msg.'</div>'; // Display our message and add a div around it with the class statusmsg
            } ?>

    </div>
        </div>
Run Code Online (Sandbox Code Playgroud)

Ser*_*rev 15

首先,将所有PHP代码移到顶部.没有它,我的代码下面不会工作.

要进行重定向,请使用:

header('Location: http://www.example.com/');
Run Code Online (Sandbox Code Playgroud)

另外,请考虑我的建议.因为它不是今天的第一个问题而你所有的问题都与基础知识有关,所以你应该考虑阅读一些好的PHP书来理解它是如何工作的.

在这里,您可以找到免费书籍的有用链接:https: //stackoverflow.com/tags/php/info


Hac*_*man 9

用PHP代码生成的Javascript重定向:

 if($match > 0){
     $msg = 'Login Complete! Thanks';
     echo "<script> window.location.assign('index.php'); </script>";
 }
 else{
     $msg = 'Login Failed!<br /> Please make sure that you enter the correct  details and that you have activated your account.';
 }
Run Code Online (Sandbox Code Playgroud)

仅限Php重定向:

<?php
    header("Location: index.php"); 
    exit;
?>
Run Code Online (Sandbox Code Playgroud)