Use memcache to prevent continuous clicks and daily clicks

Source: Internet
Author: User

1, the use of memcache to realize how many times a day, or how long to click how many times.

1<?PHP2     $memcache=memcache ();//Call Memcache3     $key=$hua.Date(' YMD ');4     if($memcache->get ($key)){5         $hua=intval($memcache->get ($key)) +1;6         $memcache->set ($key,$hua,false, 86400);7         if(intval($memcache->get ($key)) >3){8              die(' three hits per day ');9         } Ten}Else{ One         $memcache->set ($key, ' 1 ',false, 86400); A     } -  -  the     /** -      * * - * @return [type] [enclose memcache in a function] -      */ +     functionmemcache () { -         $memcache=NewMemcache; +         $memcache->connect (' 127.0.0.1 ', ' 11211 ') or die(' Can not Content Memcache '); A         if($memcache){ at             return $memcache; -}Else{ -              die(' Can not Content Memcache '); -         } -  -}

2, the use of memcache implementation of the button how often click once

1<?PHP2     $memcache=memcache ();//Call Memcache3     $key= ' Click_ '.$uid;//$uid for my unique identity4     if($memcache->get ($key)){5          die(' Please try again later! ‘);6}Else{7         $memcache->set ($key, ' 1 ',false, 10);//set the cache time to control how often you click8     }9 Ten  One     /** A      * * - * @return [type] [enclose memcache in a function] -      */ the     functionmemcache () { -         $memcache=NewMemcache; -         $memcache->connect (' 127.0.0.1 ', ' 11211 ') or die(' Can not Content Memcache '); -         if($memcache){ +             return $memcache; -}Else{ +              die(' Can not Content Memcache '); A         } at  -}

Here are some of the lessons I have summed up that make memcache some common small functions. If you have other methods or ideas you can communicate with me in the comments.

Use memcache to prevent continuous clicks and daily clicks

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.