<?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>recaptcha &#8211; LPC影子技术分享</title>
	<atom:link href="https://www.mudbest.com/tag/recaptcha/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.mudbest.com</link>
	<description>行影不离,忘之却步.</description>
	<lastBuildDate>Tue, 14 Jan 2014 02:59:18 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1</generator>
	<item>
		<title>使用google验证码防止注册机/发帖机for discuz7.2</title>
		<link>https://www.mudbest.com/%e4%bd%bf%e7%94%a8google%e9%aa%8c%e8%af%81%e7%a0%81for-discuz7-2/</link>
		
		<dc:creator><![CDATA[hkshadow]]></dc:creator>
		<pubDate>Mon, 13 Jan 2014 09:43:37 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[分享]]></category>
		<category><![CDATA[discuz]]></category>
		<category><![CDATA[recaptcha]]></category>
		<category><![CDATA[验证码]]></category>
		<guid isPermaLink="false">http://www.mudbest.com/?p=1986</guid>

					<description><![CDATA[http://bbs.mudbest.com目前已经采用google验证码方案，平时注册机/发帖机 盯得比较紧...]]></description>
										<content:encoded><![CDATA[<p>http://bbs.mudbest.com目前已经采用google验证码方案，平时注册机/发帖机 盯得比较紧，点触验证码感觉还行，只是广告不太喜欢，看到google提供了一个验证码的接口。想到将将原来的discuz默认验证码更换掉成google的验证码，就是用户体验不怎么好。</p>
<p>1、首先到https://www.google.com/recaptcha/admin/create 注册应用。<br />
2、打开http://code.google.com/p/recaptcha/downloads/list?q=label:phplib-Latest ，下载接口文件。<br />
3、拿到注册应用后得到公用key和私有key。<br />
<span id="more-1986"></span><br />
<img fetchpriority="high" decoding="async" src="http://www.mudbest.com/wp-content/uploads/2014/01/QQ截圖20140113191913.jpg" alt="google验证码" width="609" height="243" class="alignnone size-full wp-image-1996" /></p>
<p>代码修改部分：</p>
<pre class="brush: php; title: ; notranslate">
//打开discuz7.2的/include/common.inc.php文件。
require_once DISCUZ_ROOT.'./include/global.func.php';
//加载google验证码核心文件
//并设置好应用的 公有key 和 私有key
//&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;加载google验证码部分&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;
require_once(DISCUZ_ROOT.'./include/recaptchalib.php');
$publickey = &quot;6LcC8-wSAAAAAHxRk***pMW12312krfNqscyC_C1&quot;;
$privatekey = &quot;6LcC8-wSAAAAADG***-Uy53434p0IKvgzGJG2toMD&quot;;
//&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;加载google验证码部分&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;
</pre>
<p>打开discuz7.2的/include/global.func.php文件，将函数修改如下：</p>
<pre class="brush: php; title: ; notranslate">
function submitcheck($var, $allowget = 0, $seccodecheck = 0, $secqaacheck = 0) {
	$publickey = &quot;6LcC8-wSAAAAAHxRk***pMW12312krfNqscyC_C1&quot;;
        $privatekey = &quot;6LcC8-wSAAAAADG***-Uy53434p0IKvgzGJG2toMD&quot;;
	# the response from reCAPTCHA
	$resp = null;
	# the error code from reCAPTCHA, if any
	$error = null;
	
	if(empty($GLOBALS&#x5B;$var])) {
		return FALSE;
	} else {
		global $_SERVER, $seclevel, $seccode, $seccodedata, $seccodeverify, $secanswer, $_DCACHE, $_DCOOKIE, $timestamp, $discuz_uid;
		if($allowget || ($_SERVER&#x5B;'REQUEST_METHOD'] == 'POST' &amp;&amp; $GLOBALS&#x5B;'formhash'] == formhash() &amp;&amp; empty($_SERVER&#x5B;'HTTP_X_FLASH_VERSION']) &amp;&amp; (empty($_SERVER&#x5B;'HTTP_REFERER']) ||
			preg_replace(&quot;/https?:\/\/(&#x5B;^\:\/]+).*/i&quot;, &quot;\\1&quot;, $_SERVER&#x5B;'HTTP_REFERER']) == preg_replace(&quot;/(&#x5B;^\:]+).*/&quot;, &quot;\\1&quot;, $_SERVER&#x5B;'HTTP_HOST'])))) {
        		if($seccodecheck) {
                                
        				$resp = recaptcha_check_answer ($privatekey,
        						$_SERVER&#x5B;&quot;REMOTE_ADDR&quot;],
        						$_POST&#x5B;&quot;recaptcha_challenge_field&quot;],
        						$_POST&#x5B;&quot;recaptcha_response_field&quot;]);
        			
        				if (!$resp-&gt;is_valid) {
        					showmessage('submit_seccode_invalid');
        					//echo &quot;You got it!&quot;;
        				} 
        				/*
        				else {
        					# set the error code so that we can display it
        					$error = $resp-&gt;error;
        				}
        				*/
        			
        			/*
        			if(!$seclevel) {
        				$key = $seccodedata&#x5B;'type'] != 3 ? '' : $_DCACHE&#x5B;'settings']&#x5B;'authkey'].date('Ymd');
        				list($seccode, $expiration, $seccodeuid) = explode(&quot;\t&quot;, authcode($_DCOOKIE&#x5B;'secc'], 'DECODE', $key));
        				if($seccodeuid != $discuz_uid || $timestamp - $expiration &gt; 600) {
        					showmessage('submit_seccode_invalid');
        				}
        				dsetcookie('secc', '');
        			} else {
        				$tmp = substr($seccode, 0, 1);
        			}
        			seccodeconvert($seccode);
        			if(strtoupper($seccodeverify) != $seccode) {
        				showmessage('submit_seccode_invalid');
        			}
				$seclevel &amp;&amp; $seccode = random(6, 1) + $tmp * 1000000;
				
				*/
        		}
			if($secqaacheck) {
        			if(!$seclevel) {
        				list($seccode, $expiration, $seccodeuid) = explode(&quot;\t&quot;, authcode($_DCOOKIE&#x5B;'secq'], 'DECODE'));
        				if($seccodeuid != $discuz_uid || $timestamp - $expiration &gt; 600) {
        					showmessage('submit_secqaa_invalid');
        				}
        				dsetcookie('secq', '');
        			}
        			require_once DISCUZ_ROOT.'./forumdata/cache/cache_secqaa.php';
        			if(md5($secanswer) != $_DCACHE&#x5B;'secqaa']&#x5B;substr($seccode, 0, 1)]&#x5B;'answer']) {
        			        showmessage('submit_secqaa_invalid');
        			}
				$seclevel &amp;&amp; $seccode = random(1, 1) * 1000000 + substr($seccode, -6);
        		}
			return TRUE;
		} else {
			showmessage('submit_invalid');
		}
	}
}
</pre>
<p>打开discuz7.2的/templates/default/post.htm模板文件，修改以下部分：</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!--
此部分代码是由下面移到上面
--&gt;
&lt;!--{if $action != 'edit' &amp;&amp; ($secqaacheck || $seccodecheck)}--&gt;{template seccheck}&lt;!--{/if}--&gt;

&lt;button type=&quot;submit&quot; id=&quot;postsubmit&quot; prompt=&quot;post_submit&quot;  value=&quot;true&quot; name=&quot;{if $action == 'newthread'}topicsubmit{elseif $action == 'reply'}replysubmit{elseif $action == 'edit'}editsubmit{/if}&quot; tabindex=&quot;1&quot;&gt;
&lt;!--{if $action == 'newthread'}--&gt;
	&lt;!--{if $special == 0}--&gt;{lang post_newthread}
	&lt;!--{elseif $special == 1}--&gt;{lang post_newthreadpoll}
	&lt;!--{elseif $special == 2}--&gt;{lang post_newthreadtrade}
	&lt;!--{elseif $special == 3}--&gt;{lang post_newthreadreward}
	&lt;!--{elseif $special == 4}--&gt;{lang post_newthreadactivity}
	&lt;!--{elseif $special == 5}--&gt;{lang post_newthreaddebate}
	&lt;!--{elseif $special == 127}--&gt;
		&lt;!--{if $buttontext}--&gt;$buttontext&lt;!--{else}--&gt;{lang post_newthread}&lt;!--{/if}--&gt;
	&lt;!--{/if}--&gt;
&lt;!--{elseif $action == 'reply' &amp;&amp; !empty($addtrade)}--&gt;{lang trade_add_post}
&lt;!--{elseif $action == 'reply'}--&gt;{lang join_thread}
&lt;!--{elseif $action == 'edit'}--&gt;{lang edit_thread}
&lt;!--{/if}--&gt;
&lt;/button&gt;
</pre>
<p>修改seccheck.php文件，如果想以后能还原，建议备份该模板文件，该文件全部最终代码如下。</p>
<pre class="brush: xml; title: ; notranslate">
&lt;style&gt;
	#recaptcha_table{
		table-layout:auto;
	}
&lt;/style&gt;
{eval echo recaptcha_get_html($publickey)}
</pre>
<p><img decoding="async" src="http://www.mudbest.com/wp-content/uploads/2014/01/5555-610x410.jpg" alt="5555" width="610" height="410" class="alignnone size-medium wp-image-1991" srcset="https://www.mudbest.com/wp-content/uploads/2014/01/5555-610x410.jpg 610w, https://www.mudbest.com/wp-content/uploads/2014/01/5555.jpg 984w" sizes="(max-width: 610px) 100vw, 610px" /></p>
<p><img decoding="async" src="http://www.mudbest.com/wp-content/uploads/2014/01/444-610x421.jpg" alt="444" width="610" height="421" class="alignnone size-medium wp-image-1990" srcset="https://www.mudbest.com/wp-content/uploads/2014/01/444-610x421.jpg 610w, https://www.mudbest.com/wp-content/uploads/2014/01/444.jpg 920w" sizes="(max-width: 610px) 100vw, 610px" /></p>
<p>至此，google验证码已经在使用了。</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
