如何在PHP中运行另一个代码,如果代码是成功的


How to run another code in PHP, if the code is successful?

我正在学习如何使登录面板与会话从这里。我完全理解了,但是我想打开另一个文件,在那个代码中,当有人输入正确的密码+电子邮件时,它只返回You have entered valid use name and password

如何制作,清除页面上的所有内容,并打开代码(我键入的)…

可能是这样的,在我登录后,屏幕上的一切都会变得清晰,并且会打开一个图像。

您可以对登录函数这样做添加一个变量来检查该用户是否已登录

<?php
        $msg = '';
        $logedin = false;
        if (isset($_POST['login']) && !empty($_POST['username']) 
           && !empty($_POST['password'])) {
           if ($_POST['username'] == 'tutorialspoint' && 
              $_POST['password'] == '1234') {
              $_SESSION['valid'] = true;
              $_SESSION['timeout'] = time();
              $_SESSION['username'] = 'tutorialspoint';
              //echo 'You have entered valid use name and password';
              $logedin = true;
           }else {
                $logedin = false;
              $msg = 'Wrong username or password';
           }
        }
     ?>

然后检查用户是否登录,看看你将显示什么

 <div class = "container">
  //if the user is NOT logged in
    <? if($loggedin){ ?>
     <form class = "form-signin" role = "form" 
        action = "<?php echo htmlspecialchars($_SERVER['PHP_SELF']); 
        ?>" method = "post">
        <h4 class = "form-signin-heading"><?php echo $msg; ?></h4>
        <input type = "text" class = "form-control" 
           name = "username" placeholder = "username = tutorialspoint" 
           required autofocus></br>
        <input type = "password" class = "form-control"
           name = "password" placeholder = "password = 1234" required>
        <button class = "btn btn-lg btn-primary btn-block" type = "submit" 
           name = "login">Login</button>
     </form>
     Click here to clean <a href = "logout.php" tite = "Logout">Session.
     <? }else{ ?>
      // if user logged in yout code goes here
     <? } ?>
  </div> 

雅酷这么简单,后回行ie。'echo '您已经输入了有效的用户名和密码';',请使用这个或只是替换行

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

您可以在这个示例的位置使用任何链接或本地文件link