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.
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 = 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; //echo $url; if (!session_id()){session_start();}; if(isset($_GET['close'])){ $url = $_GET['url']; unset($_SESSION['recheck']); } if(isset($_POST['password']) && $_POST['password'] == '123456'){ $_SESSION['recheck'] = 1; header('location:'.$url); } if(!isset($_SESSION['recheck'])){ exit('<div id="divcss"> <form method="post"> 请输入独立访问密码:<input type="password" name="password" /> <input type="submit" value="确定" />(密码:123456) </form> </div> '); } ?> <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!