Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 提交表单后如何清除页面内容?_Php - Fatal编程技术网

Php 提交表单后如何清除页面内容?

Php 提交表单后如何清除页面内容?,php,Php,我目前在我的项目中有以下代码: require_once('mysql.inc.php'); session_start(); if (!isset($_SESSION['username']) && !isset($_SESSION['uid'])) { login_sequence(); } else { login_check($_SESSION['username'], $_SESSION['uid']); } function login_seque

我目前在我的项目中有以下代码:
require_once('mysql.inc.php');
session_start();

if (!isset($_SESSION['username']) && !isset($_SESSION['uid']))
{
    login_sequence();
}
else
{
    login_check($_SESSION['username'], $_SESSION['uid']);
}

function login_sequence()
{
    echo '<p>' . $pretext . '</p><form method="post" action="" /><label for="password">Password: </label><input type="password" name="password" id="password" /><input type="submit" value="Log In" /><input type="hidden" name="submitted" /></form>';
    if (isset($_POST['submitted']))
    {
        $pword = hash('sha256', $_POST['password']);
        $query = "SELECT pword FROM users WHERE user = 'guest'";
        $result = mysql_query($query);
        $return = mysql_fetch_assoc($result);
        if ($return['pword'] == $pword)
        {
            pageout();
        }
        else
        {
            echo 'You entered the wrong password, if you are not a member, please leave.';
        }
    }
}

function login_check($username, $uid)
{
}

function pageout()
{
    echo('
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
    "http://www.w3.org/TR/html4/strict.dtd">

    <html lang="en-US">
        <head>
            <title></title>
            <link rel="stylesheet" type="text/css" href="" />
        </head>
        <body>
            <div id="header">
            <p>WOOT</P>
            </div>
            <div id="">
            </div>
            <div id="navigation">
            </div>
            <div id="footer">
            </div>
        </body>
    </html>
    ');
}

?>
require_once('mysql.inc.php');
会话_start();
如果(!isset($_会话['username'])和(&!isset($_会话['uid']))
{
登录顺序();
}
其他的
{
登录检查($会话['username'],$会话['uid']);
}
函数登录\u序列()
{
回显“”.$pretext.“

密码:”; 如果(isset($_POST['submitted'])) { $pword=hash('sha256',$_POST['password']); $query=“从用户中选择pword,其中用户='guest'; $result=mysql\u query($query); $return=mysql\u fetch\u assoc($result); 如果($return['pword']=$pword) { pageout(); } 其他的 { echo“您输入了错误的密码,如果您不是会员,请离开”; } } } 函数登录检查($username,$uid) { } 函数pageout() { 回声(' 呜呜声

'); } ?>
数据库中存储有一个“来宾”密码,它访问数据库并将用户输入的密码与数据库中存储的密码进行核对。我想让它这样后,表格提交和信息是正确的,在同一页上的表格消失,页面出现。我该怎么做?如何去掉表单为新页面腾出空间?

简单地做

在表单末尾和php代码处执行此操作

if(!isset($\u POST['s'])){
?>
你的表格在这里

成功时的页眉(位置…),或以登录设置为条件的页面显示,我会使结构看起来略有不同:

//First
if (!isset($_POST['submitted'])) {
    //include your form only
} else {
    //Check if user submitted correct password

   //If password is correct
   if ($return['pword'] == $pword) {
       pageout();
       //OR write pageout code on different page and call header("Location: Yourpage.php");
   } else {
       //Include form or inform user about password mismatch
   }  
}
编辑。另外,如果使用标题(“位置:”)功能,请确保没有回音或包含任何输出数据的内容。这将导致标题已发送错误

//First
if (!isset($_POST['submitted'])) {
    //include your form only
} else {
    //Check if user submitted correct password

   //If password is correct
   if ($return['pword'] == $pword) {
       pageout();
       //OR write pageout code on different page and call header("Location: Yourpage.php");
   } else {
       //Include form or inform user about password mismatch
   }  
}