<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>数字验证码相关文章列表 | 皇家元林</title>
	<atom:link href="https://hjyl.org/tags/%E6%95%B0%E5%AD%97%E9%AA%8C%E8%AF%81%E7%A0%81/feed/" rel="self" type="application/rss+xml" />
	<link>https://hjyl.org</link>
	<description>刘元林的个人博客</description>
	<lastBuildDate>Mon, 05 Feb 2018 14:59:14 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://img.hjyl.org/uploads/2019/10/cropped-about-me-32x32.png</url>
	<title>数字验证码相关文章列表 | 皇家元林</title>
	<link>https://hjyl.org</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>验证码这件大事</title>
		<link>https://hjyl.org/verification-code/</link>
					<comments>https://hjyl.org/verification-code/#comments</comments>
		
		<dc:creator><![CDATA[皇家元林]]></dc:creator>
		<pubDate>Fri, 21 Feb 2014 14:39:25 +0000</pubDate>
				<category><![CDATA[元林手札]]></category>
		<category><![CDATA[垃圾评论]]></category>
		<category><![CDATA[数字验证码]]></category>
		<category><![CDATA[验证码]]></category>
		<guid isPermaLink="false">http://hjyl.org/?p=2788</guid>

					<description><![CDATA[分享一段简单四位数字验证码WordPress代码版。]]></description>
										<content:encoded><![CDATA[<p>垃圾评论是非常招人恨的事儿。曾经一段时间，为了找一款反垃圾评论插件或一段及其简单的验证码代码，奋战到深夜，以至连续好几天。对于我这种白菜，自己是不懂写代码的，但是我会用，经过不断的测试，不管代码有漏洞与否，有效果就行。当然网上的高手多不胜数，只是照顾我们这种白菜却少之又少。</p>
<p>曾经好长一段时间，我一直用那个滑动解锁式验证码，好看又好用，不过有些复杂，而且代码老不更新，貌似都不支持最新版JQ了。于是后来就放弃了。其实我就是想找款简单的数字验证码，随机的，应付非人评论足够了。一直不明白为什么有那么多乱七八糟乱码式的评论，像病毒一样。然后人为的垃圾评论，也不可能连续来上几十条吧，也太累了。不过对于七毛党，五毛党，就很难说了。</p>
<p>不废话，演示见本站。</p>
<p>将下面代码甩进functions.php即可：</p>
<pre>
// ADD: Anti-spam Code
function olo_antispam(){
   if(!is_user_logged_in()){
        //$pcodes = substr(md5(mt_rand(0,99999)),0,4); //验证码为英文+数字组合
       $pcodes = substr(mt_rand(0,99999),0,4);    //验证码为数字组合
       $str = '<p class="olo_anti">';
       $str .= '<label for="subpcodes">'.__('Anti-spam Code', 'olo').':</label>';
       $str .= '<input type="text"  size="4" id="subpcodes" name="subpcodes" />';
       $str .= '<span class="pcodes">'.$pcodes.'</span>';
       $str .= '<input type="hidden" value="'.$pcodes.'" name="pcodes" />';
       $str .= '</p>';
       echo $str;
   }
}
add_action('comment_form', 'olo_antispam', 1, 1);
function yanzhengma(){
   if ( !is_user_logged_in() ) {
       $pcodes = trim($_POST['pcodes']);
       $subpcodes = trim($_POST['subpcodes']);
       if((($pcodes)!=$subpcodes) || empty($subpcodes)){
           wp_die( __('错误提示：请输入正确的验证码。') );
       }
   }
}
add_filter('pre_comment_on_post', 'yanzhengma');
</pre>
<p>这个代码有人应该觉得很熟悉，网上复制粘贴的病毒式的扩散了很多。都说直接用yanzhengma()调用即可，可我测试了N遍，就是不行。后来我找到了答案，是在一个博客上，不记得是谁的了，做出了类似的例子，我修改了一下。这个是自动插入评论下方的，如果手动调用的话，可以将<span style="color: rgb(0, 0, 0);">add_action(&#39;comment_form&#39;, 'olo_antispam', 1, 1);</span>这段代码注释，并在需要的位置调用olo_antispam()即可。</p>
<p>好了，有问题或者有更好的建议，欢迎交流！</p>
<div id="content-copyright"><span style="font-weight:bold;text-shadow:0 1px 0 #ddd;font-size: 13px;">版权声明: </span><span style="font-size: 13px;">本文采用 <a href="https://hjyl.org/go/aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLXNhLzMuMC8=" rel="nofollow" target="_blank">BY-NC-SA</a> 协议进行授权，如无注明均为原创，转载请注明转自 <a href="https://hjyl.org">皇家元林</a><br>本文链接: <a rel="bookmark" title="验证码这件大事" href="https://hjyl.org/verification-code/">验证码这件大事</a></span></div>]]></content:encoded>
					
					<wfw:commentRss>https://hjyl.org/verification-code/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
	</channel>
</rss>
