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