-
-
Save eggfly/10f37bddd87cfe37012a1e1aa8398259 to your computer and use it in GitHub Desktop.
wordpress首页添加访问密码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!isset($_SESSION)) { | |
session_start(); | |
} | |
if( isset($_SESSION['authenticated']) ) | |
{ | |
if($_SESSION['authenticated'] == 'yes') | |
{ | |
$authenticated = 'yes'; | |
} | |
else | |
{ | |
$authenticated = 'no'; | |
} | |
} | |
else | |
{ | |
$authenticated = 'no'; | |
} | |
if($authenticated != 'yes') | |
{ | |
header("Location: http://ad.hiing.net/login.php"); //网址改为自己的网址 | |
exit(); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
// 将 west4life 改成你要设置的密码 | |
$password = 'west4life'; | |
// 将 ad.hiing.net 改成你网站首页地址,保留后面的斜杠 | |
$url = 'http://ad.hiing.net/'; | |
if(isset($_POST['password'])) { | |
$pwd = $_POST['password']; | |
if($pwd == $password) { | |
$_SESSION['authenticated'] = "yes"; | |
$do = "redirect"; | |
} | |
else { | |
$do = "incorrect"; | |
} | |
} | |
else{ | |
$do = "showform"; | |
} | |
if($do == "showform") { | |
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
// 这里自定义login.php页面的标题 | |
<title> 落落要淡定 </title> | |
<style type="text/css"> | |
body { | |
font-size:14px; | |
} | |
</style> | |
</head> | |
<body> | |
<div align="center" style="margin:100px auto;width:300px;background-color:#000;color:#FFF"> <h2>必须输入密码才能访问本博客</h2> | |
<form action="'.$url.'login.php" method="post"> | |
密码: <input name="password" type="password" /><br></br> | |
<button type="submit">登录</button> | |
<button type="reset">重置</button></form></div> | |
</form> | |
</div> | |
</body> | |
</html>'; | |
} | |
else if($do == "incorrect") { | |
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<title>输入密码访问</title> | |
<style type="text/css"> | |
body { | |
font-size:14px; | |
} | |
</style> | |
</head> | |
<body> | |
<div align="center" style="margin:100px auto;width:300px;background-color:#000;color:#FFF"> <h2>必须输入密码才能访问本博客</h2> | |
<form action="'.$url.'login.php" method="post"> | |
<div style="color:red" >刚开输入的密码不正确</div> | |
密码: <input name="password" type="password" /><br></br> | |
<button type="submit">登录</button> | |
<button type="reset">重置</button> | |
</form> | |
</div> | |
</body> | |
</html>'; | |
} | |
elseif($do == "redirect") | |
{ | |
header("Location: ".$url); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
自己制作login.php,并修改,后,上传到网站根目录 | |
将header.php中的内容添加到theme中的header.php中,第一行即可。自行修改内容。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment