在wordpress评论中,一般是根据邮箱地址来确认访客身份的,默认没有对管理员/访客进行区分。也就是说,如果我知道管理员的邮箱地址,那么就很容易冒充管理员对留言进行回复,这也是一个小的安全隐患。

嘿嘿,我教大家做坏事了,只要填上目标博客的邮箱,名字,就到处可以模仿博主留言了,欺骗性很大。欢迎到其它博客测试,没有过滤的博客可是百试百灵,我很邪恶的在万戈那里留言了。

1

为了解决这个问题,需要对邮箱地址进行过滤。把<?php以下的代码复制到 WordPress 主题文件夹下的 functions.php 中:

<?php
/**
 * when comment check the comment_author comment_author_email
 * @param unknown_type $comment_author
 * @param unknown_type $comment_author_email
 * @return unknown_type
 */
function CheckEmailAndName(){
	global $wpdb;
	$comment_author       = ( isset($_POST['author']) )  ? trim(strip_tags($_POST['author'])) : null;
	$comment_author_email = ( isset($_POST['email']) )   ? trim($_POST['email']) : null;
	if(!$comment_author || !$comment_author_email){
		return;
	}

	$result_set = $wpdb->get_results("SELECT display_name, user_email FROM $wpdb->users WHERE display_name = '" . $comment_author . "' OR user_email = '" . $comment_author_email . "'");
	if ($result_set) {
		if ($result_set[0]->display_name == $comment_author){
			$errorMessage =  __('警告: 您不能用这个昵称,因为这是我的名字!乖,不要捣乱(*^__^*)……');
		}else{
			$errorMessage = __('警告: 您不能使用该邮箱地址,因为这是我的邮箱!乖,不要捣乱(*^__^*)……');
		}
		fail($errorMessage);
	}
}
add_action('pre_comment_on_post', 'CheckEmailAndName');

欢迎童鞋们到处搞乱啊,不要说是我教坏的,:-D

  1. Fanr (2010.08.31 at 22:13) 41楼

    是啊是啊,我得赶紧弄去~~

  2. N (2010.09.04 at 11:48) 42楼

    。。。没人那么缺德吧

    • winy() (2010.09.04 at 12:11)

      @N
      有的。。

  3. 疾风 (2010.09.06 at 14:19) 43楼

    为什么提示 fail($errorMessage); 这个不对呢
    Fatal error: Call to undefined function fail()

    • winy() (2010.09.06 at 23:58)

      @疾风 ,因为你没有fail()这个函数,
      后面还需要加上:
      function fail($s) {
      header('HTTP/1.0 403 Forbidden');
      header('Content-Type: text/plain');
      if(is_string($s)){
      die($s);
      }else{
      $s;
      die;
      }
      }

      奇怪,以前都没人告诉我的。。。

  4. 严重浪漫 (2010.10.05 at 14:40) 44楼

    好玩啊
    还可以这样

评论分页: 1 ... 4 5 6

发布评论

邮箱(必填)

换个背景