簡體   English   中英

如何使用 php 為我的網站應用程序創建默認頁面?

[英]How do I make a default page for my website application with php?

所以我希望有人能給我一個簡單的功能或解決方案來在我的網站上放置一個默認頁面。 這意味着如果用戶嘗試訪問我網站的另一個頁面,他就不能。 他需要通過這個默認頁面。 因為在我的網站中,我有一個管理頁面,我不希望一個簡單的用戶訪問它。 我在互聯網上做了一些研究,但沒有找到解決問題的好答案。 有什么辦法可以簡單地通過代碼而不是更改索引文件來完成嗎? 更具體地說,我希望它僅適用於我的一個網站,而不適用於所有 . 我有一個管理員登錄系統,但由於您可以通過輸入地址而不使用登錄系統直接訪問管理頁面,這是一個問題。 我確實嘗試建立索引,但問題是當我嘗試登錄時,它會將我重定向到默認頁面而不是管理頁面。 我將不勝感激任何幫助。 最好的問候年輕的程序員。

這是 index.php

<?php

header('Location: Foredeckmain.php');
exit;
?>

這是登錄頁面

<?php
   ob_start();
   session_start();
?> 

<html lang = "en">

   <head>
      <title>Foredeck Login.com</title>
      <link href = "css/bootstrap.min.css" rel = "stylesheet">

      <style>
         body {
            padding-top: 40px;
            padding-bottom: 40px;
            background-color: #6495ED;
         }

         .form-signin {
            max-width: 330px;
            padding: 15px;
            margin: 0 auto;
            color: #000000;
         }

         .form-signin .form-signin-heading,
         .form-signin .checkbox {
            margin-bottom: 10px;
         }

         .form-signin .checkbox {
            font-weight: normal;
         }

         .form-signin .form-control {
            position: relative;
            height: auto;
            -webkit-box-sizing: border-box;
            -moz-box-sizing: border-box;
            box-sizing: border-box;
            padding: 10px;
            font-size: 16px;
         }

         .form-signin .form-control:focus {
            z-index: 2;
         }

         .form-signin input[type="text"] {
            margin-bottom: 0 px;
            border-bottom-right-radius: 0;
            border-bottom-left-radius: 0;
            border-color:#000000;
         }

         .form-signin input[type="password"] {
            margin-bottom: 10px;
            border-top-left-radius: 0;
            border-top-right-radius: 0;
            border-color:#000000;
         }

         h3{
            text-align: ;
            color: #000000;
         }
         h1{
            text-align: ;
            color: #000000;
         }
      </style>

   </head>

   <?php
        $msg = '';

        if (isset($_POST['login']) && !empty($_POST['username']) 
            && !empty($_POST['password'])) {

            if ($_POST['username'] == 'foredeck' && 
              $_POST['password'] == 'foredeck1') {
              $_SESSION['valid'] = true;
              $_SESSION['timeout'] = time();
              $_SESSION['username'] = 'foredeck';
              $msg ='Connexion Réussite';
              echo "<script type='text/javascript'>alert('Connexion Réussite');
                window.location='foredeck.php'; </script>";

              header("refresh:3 location: foredeck.php");

            }else {
              $msg='Identifiant ou Mot de Passe incorrecte';
              $msg =  "<script type='text/javascript'>alert('$msg')</script>";
               }
            }
     ?>
  </div> <!-- /container -->

  <div class = "container">

     <form class = "form-signin" role = "form" 
        action = "<?php echo htmlspecialchars($_SERVER['PHP_SELF']); 
        ?>" method = "post">
        <h4 class = "form-signin-heading"><?php echo $msg; ?></h4>
        <h1>Foredeck@Admin</h1> 
        <h3>Entrer l'identifant et le mot de passe:</h3> 
        <input type = "text" class = "form-control" 
               name = "username" placeholder = "Identifiant " 
               required autofocus></br>
        <input type = "password" class = "form-control"
               name = "password" placeholder = "Mot de passe  " required>
        <br>

        <button class = "btn btn-lg btn-primary btn-block" type = "submit" 
               name = "login">Se connecter</button>
     </form>
  </div> 
  </body>

這是注銷部分

<?php
   session_start();
   unset($_SESSION["username"]);
   unset($_SESSION["password"]);

   echo 'Déconnexion en cours...';
   header('Refresh: 2; URL = foredeckmain.php');
?>

說實話,我不明白你為什么要這樣做,但無論如何。

但如果我是你,我會采取下一步行動

  1. 配置 Apache/Nginx/或您正在使用的網站/通過您的默認頁面(index.php 或類似內容)處理您的所有請求

  2. 在 index.php 中,您需要了解您的用戶需要什么頁面。 如果它不存在,則向他顯示 404 頁面。

  3. 如果頁面存在並且它不是您的默認頁面,並且用戶之前沒有訪問過它,請將他重定向到那里。
  4. 在您的默認頁面中,寫入會話,例如$_SESSION['passed_default'] = 1;

  5. 現在,在你的 index.php 你需要檢查

    if(isset($_SESSION['passed_default']) && $_SESSION['passed_default']) { //Show desired page } else { //redirect to default }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM