douye5949 2018-03-25 04:57
浏览 102

PHP登录表单将用户引导到新页面

I've created a login form on HTML that asks for a specific username + password. (User = hello, pass = bye)

I want my PHP form to check if the user input is correct (Hello & Bye), and if so, direct the user to a page called "next.html"

Here is my login.html form

<html>

        <h1> <font color="red">Log In To Add Entry!</font></h1>

<form name="myForm" action="login.php" method="post">

<fieldset >
<legend>Login</legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>

 <label for='username' >UserName*:</label>
<input type='text' name='username' id='username'  maxlength="50" /> 

<br> <label for='password' >Password*:</label>
<input type='password' name='password' id='password' maxlength="50" />

<input type='submit' name='Submit' value='Submit' />

</fieldset>
</form>
</html>

My login.php :

<?php

function Login()
{
    if(empty($_POST['username']))
    {
        $this->HandleError("UserName is empty!");
        return false;
    }
    
    if(empty($_POST['password']))
    {
        $this->HandleError("Password is empty!");
        return false;
    }
    
    $username = trim($_POST['username']);
    $password = trim($_POST['password']);
    
    if(!$this->CheckLoginInDB($username,$password))
    {
        return false;
    }
    
    session_start();
    
    $_SESSION[$this->GetLoginSessionVar()] = $username;
    
    return true;


    
}

?>

and my next.html page, where I want the user to go if the user + password are correct:

<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns = "http://www.w3.org/1999/xhtml">

        <title>Entry page</title>
    </head>
    <body>
        <h1> <font color="red">Add an entry to Joe's Blog!</font></h1>




</html>

</div>
  • 写回答

3条回答 默认 最新

  • doupu0619 2018-03-25 05:06
    关注

    In login.php just add above;

    if( Login() ) {
         header("Location: next.html"); exit();
    }
    

    If you just want to use that one login info then replace:

    if(!$this->CheckLoginInDB($username,$password))
    

    With:

    if( $username == "hello"  && $password == "bye" )
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器