PHP隨機數生成器 paptcha

jopen 13年前發布 | 24K 次閱讀 PHP 驗證碼(Captcha)

paptcha 是一個用來生成在網頁驗證碼中使用的隨機數的PHP函數。

function paptcha() {

error_reporting ( E_ERROR );

if (is_int(func_get_arg(0)) && abs(func_get_arg(0)) < 10) $dig = abs(func_get_arg(0)); else $dig = 1;

if (is_int(func_get_arg(1)) && abs(func_get_arg(1)) < 10 && abs(func_get_arg(1)) > 1) $chs = abs(func_get_arg(1)); else $chs = 2;

for($i = 0; $i < $dig; $i++) $res .= rand(0, 9);

// I put the result to first position of the choice array $choices[0] = $res;

// File the choice array with options (numbers) for($k = 1; $k < $chs; $k++) for($i = 0; $i < $dig; $i++) $choices[$k] .= rand(0, 9);

// Mix up a little the numbers shuffle ($choices);

/*

  • I put the result to the final position of the choice array.
  • Now we know that one of the results of the array is our Captcha Choice
  • and we can verify the answer with the last number of the array */ $choices[$k] = $res; return($choices); } //end of func</pre>

    項目主頁:http://www.baiduhome.net/lib/view/home/1324534843749

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!