Home  >  Article  >  Backend Development  >  How to set password on php page

How to set password on php page

藏色散人
藏色散人Original
2021-07-16 09:29:183469browse

How to set the password on the php page: First create a recheck.php file; then include the php file at the front of the page where you need to set an independent access password.

How to set password on php page

The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer

How to set the password on the php page?

Set an independent access password for the PHP page (page encryption)

Set an independent access password for some PHP pages. If the password is incorrect, you will not be able to view the content, which is equivalent to deleting the page. an encryption. Just include the following php file at the front of where you need to set the independent access password.

recheck.php

<html>
   <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>title</title>
  <style>
#divcss{margin:300 auto;width:400px;height:40px;}   
#footer {
            height: 40px;
            line-height: 40px;
            position: fixed;
            bottom: 0;
            width: 100%;
            text-align: center;
            background: #373d41;
            color: #ffffff;
            font-family: Arial;
            font-size: 16px;
      
            letter-spacing: 1px;
        }
a {text-decoration: none}
  </style>
</head>
<body>
<?php
//所有需要输出二次密码打开的页面,只需要将本php文件进行包含即可
$url = &#39;http://&#39;.$_SERVER[&#39;SERVER_NAME&#39;].&#39;:&#39;.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
//echo $url;
if (!session_id()){session_start();};
if(isset($_GET[&#39;close&#39;])){  
$url = $_GET[&#39;url&#39;]; 
unset($_SESSION[&#39;recheck&#39;]);
}
if(isset($_POST[&#39;password&#39;]) && $_POST[&#39;password&#39;] == &#39;123456&#39;){
    $_SESSION[&#39;recheck&#39;] = 1;
    header(&#39;location:&#39;.$url);
}
if(!isset($_SESSION[&#39;recheck&#39;])){
    exit(&#39;<div id="divcss">
        <form method="post">
            请输入独立访问密码:<input type="password" name="password" />
            <input type="submit" value="确定" />(密码:123456)
        </form>
    </div>
    &#39;);
}
?>
<div id="footer"><a href="?close=yes&url=<?php echo $url?>"><font color="#FFFFFF">安全退出本页面</font></a></div>
</body>
</html>

Just include this php file in the page where you need to set an independent password for access. This will ensure that you can only access the specified page after entering the correct access password; You can also modify it slightly and encapsulate it into a function and insert it directly into the top of the page where the access password needs to be set, so that you can set a different access password for each page!

<?php include(‘recheck.php’); ?>

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to set password on php page. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn