用密码保护整个blog

WordPress 只提供对某篇文章进行密码保护,但它的标题仍然显示。如果你的Blog是写日记,可能什么都不想让外人看到。

WP支持论坛的一个主题中给出一种非常简单的解决方案,未登录用户自动被重定向到登录页面。将以下代码复制到你的Blog根目录下,并将$siteurl变量赋予正确的值(从论坛里直接复制的代码似乎有问题)。

<?php
$siteurl = 'http://your.blog.url';

$cookiehash = md5($siteurl);
if(empty($_COOKIE['wordpressuser_' . $cookiehash])) :
header('Location: /wp-login.php');
else :
define('WP_USE_THEMES', true);
require('./wp-blog-header.php');
endif;
?>

刚才朋友让我给他弄密码保护,我把自己的改了一下,然后告诉他好了。刚才上自己Blog出了问题,才想起来改错了。。。我说怎么好几个小时没收到垃圾评论呢,看来对付spam最好的办法还是──关站。

This entry was posted on Friday, February 9th, 2007 at 12:10 am and is filed under WordPress. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

3 Comments »

Comment by itsokbaby
2007-02-09 00:18:30

现在越来越无心去研究WP了…累的慌…
师兄好毅力:P

 
Comment by awflasher
2007-02-11 13:13:59

wp细节好研究,但整体研究得累

 
Comment by infanta_zhang
2007-10-23 13:24:22

我想问一下,哪里的BLOG有有文章的密码保护功能啊?麻烦你能不能用邮件告诉我,谢谢了

 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)

Please copy the string 2WAGIo to the field below: