antispamimage.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /* Copyright (C) 2005-2007 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. * or see https://www.gnu.org/
  17. */
  18. /**
  19. * \file htdocs/core/antispamimage.php
  20. * \brief Return antispam image
  21. */
  22. define('NOLOGIN', 1);
  23. if (!defined('NOREQUIREUSER')) {
  24. define('NOREQUIREUSER', 1);
  25. }
  26. if (!defined('NOREQUIREDB')) {
  27. define('NOREQUIREDB', 1);
  28. }
  29. if (!defined('NOREQUIRETRAN')) {
  30. define('NOREQUIRETRAN', 1);
  31. }
  32. if (!defined('NOREQUIREMENU')) {
  33. define('NOREQUIREMENU', 1);
  34. }
  35. if (!defined('NOREQUIRESOC')) {
  36. define('NOREQUIRESOC', 1);
  37. }
  38. if (!defined('NOTOKENRENEWAL')) {
  39. define('NOTOKENRENEWAL', 1);
  40. }
  41. require_once '../main.inc.php';
  42. /*
  43. * View
  44. */
  45. $length = 5;
  46. $letters = 'aAbBCDeEFgGhHJKLmMnNpPqQRsStTuVwWXYZz2345679';
  47. $number = strlen($letters);
  48. $string = '';
  49. for ($i = 0; $i < $length; $i++) {
  50. $string .= $letters[mt_rand(0, $number - 1)];
  51. }
  52. //print $string;
  53. $sessionkey = 'dol_antispam_value';
  54. $_SESSION[$sessionkey] = $string;
  55. $img = imagecreate(80, 32);
  56. if (empty($img)) {
  57. dol_print_error('', "Problem with GD creation");
  58. exit;
  59. }
  60. // Define mime type
  61. top_httphead('image/png', 1);
  62. $background_color = imagecolorallocate($img, 250, 250, 250);
  63. $ecriture_color = imagecolorallocate($img, 0, 0, 0);
  64. imagestring($img, 4, 24, 8, $string, $ecriture_color);
  65. imagepng($img);