PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/system/application/helpers/captcha_helper.php

https://github.com/mr-mark/mark-1
PHP | 32 lines | 28 code | 4 blank | 0 comment | 5 complexity | ef03aab1d7be3a1cc6296abc1348e06d MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. if ( ! function_exists('load_captcha')) {
  3. function load_captcha(& $title, & $output, $lang, $captcha_images_number = 4, $enclosure = "&nbsp;") {
  4. $images = array("basket", "corn", "gourd", "plant", "shovel", "sun", "sunflower", "tomato", "watercan", "wheat");
  5. $images_name = array($lang['basket'], $lang['corn'], $lang['gourd'], $lang['plant'], $lang['shovel'], $lang['sun'], $lang['sunflower'], $lang['tomato'], $lang['watercan'], $lang['wheat']);
  6. $chosen_nums = array(); //Chosen numbers
  7. $chosen_images = array(); //Chosen images
  8. $cnt = count($images);
  9. if($captcha_images_number >= $cnt) {
  10. return FALSE;
  11. }
  12. for($i = 0; $i < $captcha_images_number; $i++) {
  13. $rnd = mt_rand(0, $cnt - 1);
  14. if(array_search($rnd, $chosen_nums) === FALSE) {
  15. $chosen_nums[] = $rnd;
  16. $chosen_images[] = $images[$rnd];
  17. $output .= "<img class='captcha_img' title='" . $i . "' src='" . css_url() . "system/application/assets/images/registration/captcha/" . $images[$rnd] . ".png' />" . $enclosure;
  18. }
  19. else {
  20. $i--;
  21. }
  22. }
  23. $rnd = mt_rand(0, $captcha_images_number - 1);
  24. $title = "<span class=\"captchaText\"><B>" . $images_name[$chosen_nums[$rnd]] . "</B>" . $lang['captcha_choose']."</span>";
  25. $_SESSION['captcha'] = $rnd;
  26. return $rnd;
  27. }
  28. }