/simpleCaptcha.php

https://github.com/Bigjoos/U-232-V1 · PHP · 75 lines · 56 code · 8 blank · 11 comment · 11 complexity · 5c11561f6cadf7a50e362551bda3d6ae MD5 · raw file

  1. <?php
  2. /**
  3. * http://btdev.net:1337/svn/test/Installer09_Beta
  4. * Licence Info: GPL
  5. * Copyright (C) 2010 BTDev Installer v.1
  6. * A bittorrent tracker source based on TBDev.net/tbsource/bytemonsoon.
  7. * Project Leaders: Mindless,putyn.
  8. **/
  9. // This is the handler for captcha image requests
  10. // The captcha ID is placed in the session, so session vars are required for this plug-in
  11. session_start();
  12. // -------------------- EDIT THESE ----------------- //
  13. $images = array(
  14. 'house'=> 'captchaImages/01.png',
  15. 'key'=> 'captchaImages/04.png',
  16. 'flag'=> 'captchaImages/06.png',
  17. 'clock'=> 'captchaImages/15.png',
  18. 'bug'=> 'captchaImages/16.png',
  19. 'pen'=> 'captchaImages/19.png',
  20. 'light bulb'=> 'captchaImages/21.png',
  21. 'musical note'=> 'captchaImages/40.png',
  22. 'heart'=> 'captchaImages/43.png',
  23. 'world'=> 'captchaImages/99.png'
  24. );
  25. // ------------------- STOP EDITING ---------------- //
  26. $_SESSION['simpleCaptchaAnswer'] = null;
  27. $_SESSION['simpleCaptchaTimestamp'] = time();
  28. $SALT = "o^Gj".$_SESSION['simpleCaptchaTimestamp']."7%8W";
  29. $resp = array();
  30. header("Content-Type: application/json");
  31. if (!isset($images) || !is_array($images) || sizeof($images) < 3) {
  32. $resp['error'] = "There aren\'t enough images!";
  33. echo json_encode($resp);
  34. exit;
  35. }
  36. if (isset($_POST['numImages']) && strlen($_POST['numImages']) > 0) {
  37. $numImages = intval($_POST['numImages']);
  38. } else if (isset($_GET['numImages']) && strlen($_GET['numImages']) > 0) {
  39. $numImages = intval($_GET['numImages']);
  40. }
  41. $numImages = ($numImages > 0)?$numImages:5;
  42. $size = sizeof($images);
  43. $num = min(array($size, $numImages));
  44. $keys = array_keys($images);
  45. $used = array();
  46. mt_srand(((float) microtime() * 587) / 33);
  47. for ($i=0; $i<$num; ++$i) {
  48. $r = rand(0, $size-1);
  49. while (array_search($keys[$r], $used) !== false) {
  50. $r = rand(0, $size-1);
  51. }
  52. array_push($used, $keys[$r]);
  53. }
  54. $selectText = $used[rand(0, $num-1)];
  55. $_SESSION['simpleCaptchaAnswer'] = sha1($selectText . $SALT);
  56. $resp['text'] = ''.$selectText;
  57. $resp['images'] = array();
  58. shuffle($used);
  59. for ($i=0; $i<sizeof($used); ++$i) {
  60. array_push($resp['images'], array(
  61. 'hash'=>sha1($used[$i] . $SALT),
  62. 'file'=>$images[$used[$i]]
  63. ));
  64. }
  65. echo json_encode($resp);
  66. exit;
  67. ?>