php簡單驗證碼

@傳入所需驗證碼長度,int
@傳出所生成的驗證碼,str
@$pattern,字符池
@$length,截取長度
@$key,所得驗證碼
function randomkeys($length){
$pattern = ’1234567890abcdefghijklmnopqrstuvwxyz’;
$key=substr(str_shuffle($pattern),13,$length);
return $key;
}
php中有個隨機打亂字符串的函數str_shuffle(),然後結合substr(),就能實現生成簡單驗證碼的要求.
不知道為什麼外面生成驗證碼都用循環取字符串池的數據.不知道這兩種方式效率如何.
This entry was posted in 流水. Bookmark the permalink. Follow any comments here with the RSS feed for this post. Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

注意: 评论者允许使用'@user空格'的方式将自己的评论通知另外评论者。例如, ABC是本文的评论者之一,则使用'@ABC '(不包括单引号)将会自动将您的评论发送给ABC。使用'@all ',将会将评论发送给之前所有其它评论者。请务必注意user必须和评论者名相匹配(大小写一致)。

Chat Plugin created by Jake Ruston's Wordpress Plugins - Powered by Hardshell Laptop Cases and Ben 10 Games.