wordpress无插件纯代码实现注册验证 拒绝恶意注册

  • A+
所属分类:wordpress

wordpress能否实现注册验证功能?

最近楚狂人博客改版,花在网站上的心思多了一些,发现每天都有很多注册通知邮件发到我的邮箱里来,有点不胜其扰,哥还要专注分享免费资源和零投资网上赚钱的信息呢,哪有时间应付这些恶意注册者呢?应该找个方法给wordpress添加验证功能了。

试用的第一个方法是通过一个验证码插件,略繁琐,需要先安装geetest插件。然后还要去插件的官网注册账号,并获得密钥,回来进行插件设置之后才可以用,关键是也不知道我设置的有问题,还是需要付费,反正启用插件后前台注册时验证码总是出错,这样正常的注册会员也被挡住了,不行。

那么能否通过代码实现wordpress注册验证呢?

经过一番搜索还真找到了,把下面这段代码添加到自己的functions.php,其中的验证问题我使用了本站的域名“chukuangren.com”,你也可以改成其他内容。注意改的时候,代码第四行和倒数第四行都有,要改两处哦。

add_action( 'register_form', 'add_security_question' );
function add_security_question() { ?>
    <p>
    <label><?php _e('请输入本站域名:chukuangren.com') ?><br />
        <input type="text" name="user_proof" id="user_proof" class="input" size="25" tabindex="20" /></label>
    </p>
<?php }
     
add_action( 'register_post', 'add_security_question_validate', 10, 3 );
function add_security_question_validate( $sanitized_user_login, $user_email, $errors) {
    // 如果没有回答
    if (!isset($_POST[ 'user_proof' ]) || empty($_POST[ 'user_proof' ])) {
        return $errors->add( 'proofempty', '<strong>错误</strong>: 您还没有回答问题。'  );
    // 如果答案不正确
    } elseif ( strtolower( $_POST[ 'user_proof' ] ) != 'chukuangren.com' ) {
        return $errors->add( 'prooffail', '<strong>错误</strong>: 您的回答不正确。'  );
    }
}

效果:

wordpress无插件纯代码实现注册验证 拒绝恶意注册

注册验证

如果你觉得一个问题不过瘾,wordpress还可以实现注册随机验证:

session_start();
function rand_reg_question(){
$register_number=rand(0,2); // 设置随机数的返回范围
$_SESSION
[‘register_number’]=$register_number;
}
add_action(‘login_head’,’rand_reg_question’);

&nbsp;

global $register_questions;
global
$register_answers;
// 添加问题数组
$register_questions=array(‘中国的首都在哪里?’,’Google是哪个国家的公司?’,’楚狂人博客是用什么
建站程序搭建的?’);
// 添加答案数组(与上面的问题对应)
$register_answers=array(‘北京’,’美国’,’wordpress’);

&nbsp;

add_action(
‘register_form’, ‘add_security_question’ );
function add_security_question() {
global $register_questions;
$register_number=
$_SESSION[‘register_number’];
?&gt;
&lt;p&gt;
&lt;label&gt;&lt;?php echo $register_questions[$register_number];?&gt;&lt;br /&gt;
&lt;input type=”text”
name=”user_proof” id=”user_proof” class=”input” size=”25″ tabindex=”20″ /&gt;
&lt;/label&gt;
&lt;/p&gt;
&lt;?php }

&nbsp;

add_action( ‘register_post’,
‘add_security_question_validate’, 10, 3 );
function add_security_question_validate( $sanitized_user_login, $user_email,
$errors) {
global $register_answers;
$register_number=$_SESSION[‘register_number’];
if (!isset($_POST[ ‘user_proof’ ]) ||
empty($_POST[ ‘user_proof’ ])) {
return $errors-&gt;add( ‘proofempty’, ‘&lt;strong&gt;错误&lt;/strong&gt;: 您还没有回答问题。’ );
} elseif (
strtolower( $_POST[ ‘user_proof’ ] ) != $register_answers[$register_number] ) {
return $errors-&gt;add( ‘prooffail’, ‘&lt;strong&gt;
错误&lt;/strong&gt;: 您的回答不正确。’ );
}
}

这个功能本站没有启用,就不给大家测试,需要使用wordpress随机注册验证的朋友可以自行测试一下,祝你成功!

软件库

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:1   其中:访客  1   博主  0

    • avatar Project Runway Seasons 1-12 dvd collection 0

      I’ve been browsing online more than three hours today, yet I never found any
      interesting article like yours. It’s pretty worth enough for me.
      In my opinion, if all web owners and bloggers made good content
      as you did, the internet will be a lot more useful than ever before.|
      I couldn’t refrain from commenting. Perfectly written!|
      I’ll immediately seize your rss feed as I can not find your email subscription link or
      newsletter service. Do you’ve any? Kindly let me
      recognize in order that I may just subscribe.
      Thanks.|
      It is perfect time to make some plans for the future and it’s time to be happy.

      I have read this post and if I could I wish to suggest you few interesting
      things or advice. Perhaps you can write next articles referring to this article.
      I wish to read even more things about it!|
      It’s perfect time to make a few plans for the future
      and it’s time to be happy. I’ve learn this put up and if I may I desire to recommend
      you some fascinating things or advice. Maybe you could write subsequent articles
      regarding this article. I desire to learn more things approximately it!|
      I have been browsing online greater than three hours
      today, but I by no means discovered any attention-grabbing article like yours.
      It is lovely value enough for me. In my view, if all web owners and bloggers made
      just right content as you probably did, the net shall be a
      lot more helpful than ever before.|
      Ahaa, its nice discussion concerning this piece of writing here at this web site, I have read all that,
      so now me also commenting at this place.|
      I am sure this article has touched all the internet
      visitors, its really really pleasant piece of writing on building
      up new web site.|
      Wow, this piece of writing is pleasant, my younger sister is analyzing these kinds of things, therefore I am going to convey her.|
      Saved as a favorite, I like your site!|
      Way cool! Some extremely valid points! I appreciate you penning this post and the rest of the site is also really good.|
      Hi, I do think this is an excellent website. I stumbledupon it
      ;) I am going to return yet again since i have book-marked it.
      Money and freedom is the best way to change, may you
      be rich and continue to help other people.|
      Woah! I’m really enjoying the template/theme of this website.
      It’s simple, yet effective. A lot of times it’s challenging to get that “perfect balance” between user
      friendliness and visual appearance. I must say you’ve done a excellent job with this.
      In addition, the blog loads super fast for me on Internet explorer.
      Outstanding Blog!|
      These are genuinely fantastic ideas in regarding blogging. You have touched some pleasant things here.
      Any way keep up wrinting.|
      I love what you guys are usually up too. This kind of
      clever work and reporting! Keep up the very good works
      guys I’ve you guys to blogroll.|
      Hey! Someone in my Myspace group shared this site with us so I came to take a look.
      I’m definitely loving the information. I’m bookmarking and will be tweeting this to
      my followers! Great blog and fantastic style and design.|
      I like what you guys tend to be up too. This sort of clever work and
      reporting! Keep up the excellent works guys I’ve incorporated
      you guys to my personal blogroll.|
      Hello would you mind sharing which blog platform you’re using?
      I’m planning to start my own blog soon but I’m having a tough time selecting between BlogEngine/Wordpress/B2evolution and Drupal.
      The reason I ask is because your layout seems different then most blogs and I’m looking
      for something unique. P.S Apologies
      for being off-topic but I had to ask!|
      Hi there would you mind letting me know which web
      host you’re working with? I’ve loaded your
      blog in 3 different internet browsers and I must say this blog loads a
      lot quicker then most. Can you suggest a good
      hosting provider at a reasonable price? Thanks a lot, I appreciate it!|
      Everyone loves it when people get together and share views.
      Great website, keep it up!|
      Thank you for the auspicious writeup. It in fact was a amusement account it.
      Look advanced to far added agreeable from you! By the way,
      how could we communicate?|
      Hi there just wanted to give you a quick heads up. The text in your post seem
      to be running off the screen in Internet explorer.
      I’m not sure if this is a format issue or something to do with internet browser compatibility but
      I thought I’d post to let you know. The design look great though!
      Hope you get the issue fixed soon. Kudos|
      This is a topic that is close to my heart… Best wishes!
      Exactly where are your contact details though?|
      It’s very effortless to find out any topic on net as compared to books, as I found this article at this
      web page.|
      Does your website have a contact page? I’m having a tough time locating it but, I’d like
      to send you an email. I’ve got some recommendations for your blog
      you might be interested in hearing. Either way, great site and I look forward
      to seeing it develop over time.|
      Greetings! I’ve been following your website
      for some time now and finally got the bravery to go ahead and
      give you a shout out from Huffman Tx! Just wanted to
      mention keep up the good work!|
      Greetings from Colorado! I’m bored to tears at work
      so I decided to check out your site on my iphone during lunch
      break. I love the info you present here and can’t wait to take a look when I get home.
      I’m amazed at how fast your blog loaded on my mobile ..
      I’m not even using WIFI, just 3G .. Anyways, amazing site!|
      Its such as you learn my thoughts! You appear to know so much about this, like you wrote the book
      in it or something. I feel that you could do with a few p.c.
      to power the message home a little bit, but instead of that, that is wonderful blog.
      An excellent read. I will certainly be back.|
      I visited multiple websites except the audio feature for audio songs current at this site is really fabulous.|
      Hi there, i read your blog occasionally and i own a similar one and i was just wondering if
      you get a lot of spam responses? If so how do you protect against
      it, any plugin or anything you can suggest? I get so much lately it’s driving me mad so any help is very much appreciated.|
      Greetings! Very helpful advice within this post! It’s the little changes which will
      make the most important changes. Thanks for sharing!|
      I seriously love your blog.. Pleasant colors & theme.
      Did you build this site yourself? Please reply back as I’m
      hoping to create my own website and would love to learn where you got this from or what the theme is called.
      Thanks!|
      Hi there! This blog post could not be written any better!
      Looking at this article reminds me of my previous roommate!

      He constantly kept talking about this. I most certainly will forward this post to him.
      Pretty sure he’ll have a great read. Thanks for sharing!|
      Wow! This blog looks just like my old one! It’s on a
      totally different topic but it has pretty much the same
      page layout and design. Superb choice of colors!|
      There is definately a great deal to find out about this issue.
      I love all of the points you’ve made.|
      You made some decent points there. I checked on the web for more information about the issue and found
      most people will go along with your views on this site.|
      Hello, I log on to your blog regularly. Your story-telling
      style is awesome, keep doing what you’re doing!|
      I simply could not depart your site prior to suggesting that I really enjoyed the standard info an individual provide in your visitors?
      Is going to be back incessantly in order to check out new posts|
      I want to to thank you for this good read!! I definitely enjoyed every little bit of
      it. I’ve got you book-marked to check out new things you post…|
      What’s up, just wanted to say, I loved this post. It was helpful.

      Keep on posting!|
      Hi there, I enjoy reading through your article.

      I like to write a little comment to support you.|
      I always spent my half an hour to read this weblog’s posts all the
      time along with a cup of coffee.|
      I for all time emailed this web site post page to all my friends,
      since if like to read it then my links will too.|
      My programmer is trying to convince me to move
      to .net from PHP. I have always disliked the idea because of the
      expenses. But he’s tryiong none the less. I’ve been using Movable-type on several websites for about a year and am anxious about switching
      to another platform. I have heard excellent things about blogengine.net.
      Is there a way I can import all my wordpress posts into it?
      Any help would be greatly appreciated!|
      Hello there! I could have sworn I’ve visited this web site before but
      after browsing through many of the articles I realized it’s new to me.
      Anyways, I’m definitely delighted I came across it and I’ll
      be bookmarking it and checking back regularly!|
      Wonderful article! This is the kind of information that are supposed to be shared around
      the web. Disgrace on the seek engines for no longer positioning this publish upper!

      Come on over and talk over with my website .

      Thank you =)|
      Heya i’m for the first time here. I found this board and I find
      It really useful & it helped me out much. I hope to give something back and help others like you aided me.|
      Hello there, I believe your blog could be having internet browser compatibility issues.
      Whenever I take a look at your blog in Safari, it looks fine however when opening in Internet Explorer,
      it has some overlapping issues. I merely wanted to give you a quick heads up!
      Besides that, fantastic website!|
      A person essentially lend a hand to make seriously articles I would state.
      That is the first time I frequented your web page and to this point?
      I surprised with the research you made to make this actual publish extraordinary.
      Great process!|
      Heya i am for the primary time here. I found this board and I find It really useful & it helped me out a lot.
      I hope to provide one thing back and help others such as you aided me.|
      Howdy! I just wish to offer you a big thumbs up for your
      great info you have got here on this post.

      I will be returning to your site for more soon.|
      I all the time used to study article in news papers but now as I am
      a user of net therefore from now I am using net for posts, thanks to
      web.|
      Your mode of describing all in this post is actually pleasant, every one can effortlessly understand
      it, Thanks a lot.|
      Hi there, I discovered your blog by means of Google while looking for a similar topic, your web site got here up, it
      appears good. I’ve bookmarked it in my google bookmarks.
      Hi there, just was aware of your blog via Google, and found that it’s really informative.
      I am going to be careful for brussels. I will appreciate in the event you
      proceed this in future. A lot of folks will probably be benefited from your writing.
      Cheers!|
      I’m curious to find out what blog platform you are utilizing?
      I’m having some minor security problems with my latest website and I’d like to find something more safe.
      Do you have any recommendations?|
      I am extremely impressed with your writing skills as well as with the layout
      on your blog. Is this a paid theme or did you customize it yourself?

      Anyway keep up the nice quality writing, it’s rare to see a great blog like this one today.|
      I am really impressed along with your writing
      skills as well as with the format to your
      blog. Is this a paid subject matter or did you customize it yourself?
      Either way stay up the nice high quality writing, it is rare to see a nice
      weblog like this one these days..|
      Hello, Neat post. There is a problem together with your website in internet explorer, might test this?
      IE still is the marketplace leader and a large component of folks will leave out your magnificent
      writing due to this problem.|
      I am not sure where you’re getting your information, but good topic.
      I needs to spend some time learning much more or understanding more.
      Thanks for excellent info I was looking for this
      info for my mission.|
      Hello, i think that i saw you visited my web site thus i came to
      “return the favor”.I am trying to find things to enhance my web site!I
      suppose its ok to use a few of \