/simpleCaptcha.php

https://github.com/Bigjoos/U-232-V3 · PHP · 72 lines · 60 code · 0 blank · 12 comment · 11 complexity · 9a8acab4fa8a62f1cb3c70d3b16d7d30 MD5 · raw file

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