如何仅在会话开始或正在进行时显示按钮?

时间:2016-01-17 05:32:27

标签: php session

我试图显示一个按钮,将我带到受密码保护的页面,但前提是登录后会话已经启动

这是在我的home.php:

<?php
 if ($_SESSION['loggedin'] = true) {      
        echo '<form action="admin.php" method="POST">       
<input type="submit" name="submit" value=" admin page"/></form>';                 
}
?>

这是我的登录页面中的代码:

session_start();
 //Was the submit button pressed?
if (isset($_POST['submit'])) {      
            //Check they entered the correct username/password       
            if ($_POST['username'] === 'csy2028' && $_POST['password'] === 'secret') {       
                $_SESSION['loggedin'] = true;
                echo '<h1>Weclome ' . $_POST['username'] .'</h1>';                
                echo '<p>This is a password secured page!</p>';    
                header( "Location: admin.php" );    

        }        
        //If they didn't, display an error message      
            else {        
                echo '<h1>Try Again...</h1>';   
                echo '<p>You did not enter the correct username and password t</p>';   
                echo'<form action="login.php" method="POST">       
                            <label>Username: </label>        
                            <input type="text" name="username" />      
                            <br>
                            </br> 
                            <label>Password: </label>        
                            <input type="password" name="password" />
                            <br>
                            </br> 
                            <input type="submit" name="submit" value=" Log In" /> </form>';


            }

0 个答案:

没有答案