users
[ class tree: users ] [ index: users ] [ all elements ]

Source for file captcha_image.php

Documentation is available at captcha_image.php

  1. <?php
  2. /**
  3.  * captcha image
  4.  *
  5.  * @copyright (c) 2004-15 bitweaver.org
  6.  *
  7.  * @package users
  8.  * @subpackage functions
  9.  */
  10.  
  11. /**
  12.  * required setup
  13.  */
  14. require_once( '../kernel/setup_inc.php' );
  15.  
  16. // dimensions
  17. $width  = @BitBase::verifyId( $_REQUEST['width'] ) ? $_REQUEST['width'] : 140;
  18. $height = @BitBase::verifyId( $_REQUEST['height'] ) ? $_REQUEST['height'] : 35;
  19.  
  20. $img = @imagecreate( $width, $height ) or die( "The GD image library doesn't seem to be available or doesn't have JPG support." );
  21.  
  22. // colours
  23. $text[] = imagecolorallocate( $img, 0  , 0  , 128 );
  24. $text[] = imagecolorallocate( $img, 0  , 128, 0   );
  25. $text[] = imagecolorallocate( $img, 128, 0  , 0   );
  26. $text[] = imagecolorallocate( $img, 0  , 128, 128 );
  27. $text[] = imagecolorallocate( $img, 128, 128, 0   );
  28. $text[] = imagecolorallocate( $img, 128, 0  , 128 );
  29. $border = imagecolorallocate( $img, 0  , 0  , 0   );
  30. $bg     = imagecolorallocate( $img, 230, 240, 250 );
  31.  
  32. imagefill( $img, 0, 0, $bg );
  33. imagerectangle( $img, 1, 1, $width - 1, $height - 1, $border );
  34. srand( time() );
  35. $number = rand( 10000, 99999 );
  36. $_SESSION['captcha'] = md5( $number );
  37. for( $i = 0; $i < 5; $i++ ) {
  38.     imagestring( $img, 10, ( $width / 6 ) - 5 + ( $width / 6 ) * $i + rand( 0, 2 ), 2 + rand( 0, $height - 22 ), substr( $number, $i, 1 ), $text[rand( 0, count( $text ) - 1 )] );
  39. }
  40.  
  41. $gd = gd_info();
  42. if( $gd["PNG Support"] ) {
  43.     header( "Content-type: image/png" );
  44.     imagepng( $img );
  45. } elseif( $gd["GIF Create Support"] ) {
  46.     header( "Content-type: image/gif" );
  47.     imagegif( $img );
  48. } else {
  49.     header( "Content-type: image/jpeg" );
  50.     imagejpeg( $img );
  51. }
  52. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:14 +0000 by phpDocumentor 1.5.0-lsces