search
HomeBackend DevelopmentPHP ProblemHow to set password on php page

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function