antispamimage.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 <http://www.gnu.org/licenses/>.
  16. * or see http://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')) define('NOREQUIREUSER',1);
  24. if (! defined('NOREQUIREDB')) define('NOREQUIREDB',1);
  25. if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN',1);
  26. if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU',1);
  27. if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC',1);
  28. if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1);
  29. require_once '../main.inc.php';
  30. /*
  31. * View
  32. */
  33. $length=5;
  34. $letters = 'aAbBCDeEFgGhHJKLmMnNpPqQRsStTuVwWXYZz2345679';
  35. $number = strlen($letters);
  36. $string = '';
  37. for($i = 0; $i < $length; $i++)
  38. {
  39. $string .= $letters{mt_rand(0, $number - 1)};
  40. }
  41. //print $string;
  42. $sessionkey='dol_antispam_value';
  43. $_SESSION[$sessionkey]=$string;
  44. $img = imagecreate(80,32);
  45. if (empty($img))
  46. {
  47. dol_print_error('',"Problem with GD creation");
  48. exit;
  49. }
  50. // Define mime type
  51. top_httphead('image/png');
  52. $background_color = imagecolorallocate($img, 250, 250, 250);
  53. $ecriture_color = imagecolorallocate($img, 0, 0, 0);
  54. imagestring($img, 4, 24, 8, $string, $ecriture_color);
  55. imagepng($img);