成功登录后重定向到新页面 [英] Redirecting to a new page after successful login

查看:162
本文介绍了成功登录后重定向到新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确信这个问题以前曾被问过,但我已经彻底搜寻了一个答案,但无济于事。 (我看到的唯一答案涉及ajax)但我只使用JavaScript,PHP和HTML。



我有一个login.php页面,并且已经创建一个HTML页面,在用户成功登录后成为着陆页面。我该怎么做?



以下是我的登录页面代码并且登录后的登录页面被称为transfer.html:



LOGIN.PHP

 < div id =content> 
< h3>登入网上银行< / h3>
< form id =loginaction =method =post>
< p>
< label for =userid> UserID:< / label>
< input type =textname =UserIDid =UserID/>
< / p>
< p>
< label for =PIN> PIN:< / label>
< input type =passwordname =PINid =PIN/>
< / p>

< p>
< input type =submitname =btnSendvalue =Loginclass =submit_button/>

< / p>
< / form>
< td>& nbsp;< / td>
< p>
尚未注册?
< a href =registration.php>点击此处注册< / a>
< / p>

< div id =wrap>
<! - 启动PHP代码 - >
<?php

mysql_connect(localhost,root,)或die(mysql_error()); //用UserID和PIN连接到数据库服务器(localhost)。
mysql_select_db(registrations)或死(mysql_error()); //选择注册数据库。 $($ set $($ _ POST ['name'])&&!empty($ _ POST ['name'])AND isset($ _ POST ['PIN'])&& !($ _ POST ['PIN'])){
$ UserID = mysql_escape_string($ _ POST ['name']);
$ PIN = mysql_escape_string(md5($ _ POST ['PIN']));

$ search = mysql_query(选择用户ID,PIN,活动FROM用户WHERE UserID ='。$ UserID。''AND PIN ='。$ PIN。'AND active ='1' )或死(mysql_error());
$ match = mysql_num_rows($ search);

if($ match> 0){
$ msg ='登录完成!谢谢';
} else {
$ msg ='登录失败!< br />请确保您输入了正确的详细信息并且已经激活了您的帐户。
}
}


?>
<! - 停止PHP代码 - >
<?php
if(isset($ msg)){//检查$ msg是否为空
echo'< div class =statusmsg>'。$ msg 。 '< / DIV>'; //显示我们的消息并在类中添加一个div statusmsg
}?>

< / div>
< / div>


解决方案

首先,将所有PHP代码移到最佳。没有它,我的代码不会工作。



要做重定向,请使用:

  header('Location:http://www.example.com/'); 

另外,请考虑我的建议。由于这不是今天的第一个问题,所有的问题都与基础有关,所以您应该考虑阅读一些很好的PHP书籍,以了解工作原理。

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


I'm sure this question has been asked before but I have searched thoroughly for an answer but to no avail. (The only answers I've seen involve ajax) But I'm using just javascript, PHP and HTML.

I have a login.php page and I have already created a HTML page which is to be the landing page right after a user is successfully logged in. How do I go about this?

The following is my code for the login page and the landing page after the login is called 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>

解决方案

First of all, move all your PHP code to the top. Without it, my code below wont work.

To do the redirect, use:

header('Location: http://www.example.com/');

Also, please consider my advice. Since it's not the first question today and all your questions are related to basics, you should consider reading some good PHP book to understand how things work.

Here you can find useful links to free books: https://stackoverflow.com/tags/php/info

这篇关于成功登录后重定向到新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆