找回密码
 立即注册

如何给网站加一个密码访问?

2022-7-24 00:28:44 · 站长社区

有些时候我们网站内容只让指定的人看见。所以就需要密码访问。我百度上找了一下 都不咋好用,我这里发一个ui美化了的也是我自己用的
1.jpg

直接复制粘贴到需要加密的页面,就可以给网站开启了密码保护,让页面输入密码才能访问!

修改也非常简单,直接替换4行密码,替换48行要跳转的链接即可。

  1. <?php  
  2. header('Content-type:text/html;charset=utf-8');
  3. $password = "zhidianyun"; // 这里是正确密码  
  4. $p = "";  
  5. if(isset($_COOKIE["isview"]) && $_COOKIE["isview"] == $password){  
  6. $isview = true;  
  7. }else{  
  8. if(isset($_POST["pwd"])){  
  9. if($_POST["pwd"] == $password){  
  10. setcookie("isview",$_POST["pwd"],time()+3600*0.2);  
  11. $isview = true;  
  12. }else{  
  13. $p = (empty($_POST["pwd"])) ? "需要密码才能查看,请输入密码。" : "密码不正确,请重新输入。";  
  14. }  
  15. }else{  
  16. $isview = false;  
  17. $p = "禁止访问";  
  18. }  
  19. }  
  20.   
  21. if($isview){ ?>

  22. <!DOCTYPE html>
  23. <html><head>
  24. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  25. <meta charset="utf-8">
  26. <title>演示</title>
  27. <p>演示</p>
  28. </body>
  29. </html>
  30. <?php }else{ ?>  
  31. <!DOCTYPE html>
  32. <html><head>
  33. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  34. <meta charset="utf-8">
  35. <title>本站开启了验证码保护</title>
  36. <meta name="keywords" content="PHP加密">
  37. <meta name="description" content="PHP加密">
  38. <style type="text/css">
  39. html{background-color:#FFF}body,button,input{font:14px/20px "Microsoft Yahei","Helvetica Neue",Helvetica,Arial,sans-serif}body{color:#585858;letter-spacing:1px}i{font-style:normal}p{margin:0}a{color:#007aff;text-decoration:none}a:hover{color:#0065ea;text-decoration:underline}button,i,img,input{vertical-align:middle}.tc{text-align:center}.auto{margin:0 auto}.mb20{margin-bottom:20px}.fl{float:left;display:inline}.oh{overflow:hidden}.fr{float:right}.i1{display:inline-block;margin-right:10px;width:80px;height:80px;border:1px solid #007aff;-webkit-border-radius:50%;-moz-border-radius:50%;border-radius:50%}.i1 img{margin-top:18px}.i2,.i2 span{position:absolute}.i2{left:123px;margin-top:-1px;bottom:-.5em;color:#dcdcdc;font:20px/1em Arial,Helvetica,sans-serif}.i2 span{color:#FFF;left:0;top:2px}.hd{font-weight:400;padding:20px 0;width:568px;margin-top:10%;border-bottom:1px solid #dcdcdc;position:relative}.bd{width:370px}.int1{border:1px solid #DDD;line-height:20px;padding:5px 10px;width:8em}.int1:focus{border-color:#007aff}.btn1{cursor:pointer;display:block;width:100%;line-height:20px;padding:5px 0;background-color:#007aff;color:#FFF;border:none 0}.btn1:hover{background-color:#0065ea}.p2_s1 img{margin:0 20px}.p2_s2{padding-top:5px}.p3{font-size:12px;color:#737373;margin-top:30px}</style>
  40. </head>
  41. <body>
  42. <h1 class="hd auto tc mb20"><i class="i1"><img src="https://pic1.zhimg.com/80/v2-dfeb5bdc6c835bb98eef84d99a293cdf_720w.jpg" width="39" height="48" src="22"></i>本站开启了密码保护<i class="i2">◆<span>◆</span></i></h1>
  43. <form id="captcha_form" class="bd auto" action="http://bbs.lxh5068.com/10169.html" method="post">
  44. <p class="mb20"><?php echo $p; ?></p>
  45. <p class="mb20 oh">
  46. <span class="fl p2_s1">
  47. <input type="password" name="pwd" placeholder="请输入密码" class="int1" autocomplete="off">
  48. </span></p>
  49. <input type="submit" value="提交" class="btn1"></input>
  50. </form>
  51. </body></html>
  52. <?php  
  53. } ?>
复制代码


全部评论 0


有些时候我们网站内容只让指定的人看见。所以就需要密码访问。我百度上找了一下 都不咋好用,我这里发一个ui美化了的也是我自己用的
1.jpg

直接复制粘贴到需要加密的页面,就可以给网站开启了密码保护,让页面输入密码才能访问!

修改也非常简单,直接替换4行密码,替换48行要跳转的链接即可。

  1. <?php  
  2. header('Content-type:text/html;charset=utf-8');
  3. $password = "zhidianyun"; // 这里是正确密码  
  4. $p = "";  
  5. if(isset($_COOKIE["isview"]) && $_COOKIE["isview"] == $password){  
  6. $isview = true;  
  7. }else{  
  8. if(isset($_POST["pwd"])){  
  9. if($_POST["pwd"] == $password){  
  10. setcookie("isview",$_POST["pwd"],time()+3600*0.2);  
  11. $isview = true;  
  12. }else{  
  13. $p = (empty($_POST["pwd"])) ? "需要密码才能查看,请输入密码。" : "密码不正确,请重新输入。";  
  14. }  
  15. }else{  
  16. $isview = false;  
  17. $p = "禁止访问";  
  18. }  
  19. }  
  20.   
  21. if($isview){ ?>

  22. <!DOCTYPE html>
  23. <html><head>
  24. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  25. <meta charset="utf-8">
  26. <title>演示</title>
  27. <p>演示</p>
  28. </body>
  29. </html>
  30. <?php }else{ ?>  
  31. <!DOCTYPE html>
  32. <html><head>
  33. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  34. <meta charset="utf-8">
  35. <title>本站开启了验证码保护</title>
  36. <meta name="keywords" content="PHP加密">
  37. <meta name="description" content="PHP加密">
  38. <style type="text/css">
  39. html{background-color:#FFF}body,button,input{font:14px/20px "Microsoft Yahei","Helvetica Neue",Helvetica,Arial,sans-serif}body{color:#585858;letter-spacing:1px}i{font-style:normal}p{margin:0}a{color:#007aff;text-decoration:none}a:hover{color:#0065ea;text-decoration:underline}button,i,img,input{vertical-align:middle}.tc{text-align:center}.auto{margin:0 auto}.mb20{margin-bottom:20px}.fl{float:left;display:inline}.oh{overflow:hidden}.fr{float:right}.i1{display:inline-block;margin-right:10px;width:80px;height:80px;border:1px solid #007aff;-webkit-border-radius:50%;-moz-border-radius:50%;border-radius:50%}.i1 img{margin-top:18px}.i2,.i2 span{position:absolute}.i2{left:123px;margin-top:-1px;bottom:-.5em;color:#dcdcdc;font:20px/1em Arial,Helvetica,sans-serif}.i2 span{color:#FFF;left:0;top:2px}.hd{font-weight:400;padding:20px 0;width:568px;margin-top:10%;border-bottom:1px solid #dcdcdc;position:relative}.bd{width:370px}.int1{border:1px solid #DDD;line-height:20px;padding:5px 10px;width:8em}.int1:focus{border-color:#007aff}.btn1{cursor:pointer;display:block;width:100%;line-height:20px;padding:5px 0;background-color:#007aff;color:#FFF;border:none 0}.btn1:hover{background-color:#0065ea}.p2_s1 img{margin:0 20px}.p2_s2{padding-top:5px}.p3{font-size:12px;color:#737373;margin-top:30px}</style>
  40. </head>
  41. <body>
  42. <h1 class="hd auto tc mb20"><i class="i1"><img src="https://pic1.zhimg.com/80/v2-dfeb5bdc6c835bb98eef84d99a293cdf_720w.jpg" width="39" height="48" src="22"></i>本站开启了密码保护<i class="i2">◆<span>◆</span></i></h1>
  43. <form id="captcha_form" class="bd auto" action="http://bbs.lxh5068.com/10169.html" method="post">
  44. <p class="mb20"><?php echo $p; ?></p>
  45. <p class="mb20 oh">
  46. <span class="fl p2_s1">
  47. <input type="password" name="pwd" placeholder="请输入密码" class="int1" autocomplete="off">
  48. </span></p>
  49. <input type="submit" value="提交" class="btn1"></input>
  50. </form>
  51. </body></html>
  52. <?php  
  53. } ?>
复制代码


热门推荐
您需要登录后才可以回帖 立即登录
说说你的想法......
0
0
0
返回顶部