PageRenderTime 23ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/nukeviet/includes/core/captcha.php

http://nuke-viet.googlecode.com/
PHP | 107 lines | 79 code | 21 blank | 7 comment | 6 complexity | 0d17c43432075824fcc26fa47731c57c MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * @Project NUKEVIET 3.x
  4. * @Author VINADES.,JSC (contact@vinades.vn)
  5. * @copyright 2009
  6. * @createdate 12/28/2009 23:50
  7. */
  8. if ( ! defined( 'NV_MAINFILE' ) ) die( 'Stop!!!' );
  9. if( $global_config['captcha_type'] == 1 )
  10. {
  11. require NV_ROOTDIR . '/includes/class/SimpleCaptcha.class.php';
  12. $captcha = new SimpleCaptcha();
  13. if( file_exists( NV_ROOTDIR . '/includes/keywords/ccaptcha_' . NV_LANG_INTERFACE . '.php' ) )
  14. {
  15. $captcha->wordsFile = 'keywords/ccaptcha_' . NV_LANG_INTERFACE . '.php';
  16. }
  17. else
  18. {
  19. $captcha->wordsFile = 'keywords/captcha_vi.php';
  20. }
  21. $captcha->session_var = 'scaptcha';
  22. $captcha->width = NV_GFX_WIDTH;
  23. $captcha->height = NV_GFX_HEIGHT;
  24. $captcha->minWordLength = NV_GFX_NUM;
  25. $captcha->maxWordLength = NV_GFX_NUM;
  26. $captcha->Yperiod = 1;
  27. $captcha->Yamplitude = 0;
  28. $captcha->Xperiod = 1;
  29. $captcha->Xamplitude = 0;
  30. $captcha->maxRotation = 30;
  31. $captcha->scale = 3;
  32. $captcha->debug = false;
  33. $captcha->backgroundColor = array(228, 228, 228);
  34. $captcha->resourcesPath = NV_ROOTDIR . '/includes';
  35. $captcha->CreateImage();
  36. die();
  37. }
  38. else
  39. {
  40. mt_srand( ( double )microtime() * 1000000 );
  41. $maxran = 1000000;
  42. $random_num = mt_rand( 1, $maxran );
  43. $nv_Request->set_Session( 'random_num', $random_num );
  44. $datekey = date( "F j" );
  45. $rcode = strtoupper( md5( NV_USER_AGENT . $global_config['sitekey'] . $random_num . $datekey ) );
  46. $code = substr( $rcode, 2, NV_GFX_NUM );
  47. $image = imagecreate( NV_GFX_WIDTH, NV_GFX_HEIGHT );
  48. $bgc = imagecolorallocate( $image, 240, 240, 240 );
  49. imagefilledrectangle( $image, 0, 0, NV_GFX_WIDTH, NV_GFX_HEIGHT, $bgc );
  50. $text_color = ImageColorAllocate( $image, 50, 50, 50 );
  51. /* output each character */
  52. for ( $l = 0; $l < 5; ++$l )
  53. {
  54. $r = mt_rand( 120, 255 );
  55. $g = mt_rand( 120, 255 );
  56. $b = mt_rand( 120, 255 );
  57. $color_elipse = ImageColorAllocate( $image, round( $r * 0.90 ), round( $g * 0.90 ), round( $b * 0.90 ) );
  58. $cx = mt_rand( 0, NV_GFX_WIDTH - NV_GFX_HEIGHT );
  59. $cy = mt_rand( 0, NV_GFX_WIDTH - NV_GFX_HEIGHT );
  60. $rx = mt_rand( 10, NV_GFX_WIDTH - NV_GFX_HEIGHT );
  61. $ry = mt_rand( 10, NV_GFX_WIDTH - NV_GFX_HEIGHT );
  62. ImageFilledEllipse( $image, $cx, $cy, $rx, $ry, $color_elipse );
  63. }
  64. $r = mt_rand( 0, 100 );
  65. $g = mt_rand( 0, 100 );
  66. $b = mt_rand( 0, 100 );
  67. $text_color = ImageColorAllocate( $image, $r, $g, $b );
  68. $ff = mt_rand( 1, 15 );
  69. $font = NV_ROOTDIR . "/includes/fonts/captcha/font" . $ff . ".ttf";
  70. if ( file_exists( $font ) and nv_function_exists( 'imagettftext' ) )
  71. {
  72. imagettftext( $image, 15, 0, 5, NV_GFX_HEIGHT - 3, $text_color, $font, $code );
  73. }
  74. else
  75. {
  76. ImageString( $image, 5, 20, 6, $code, $text_color );
  77. }
  78. Header( "Content-type: image/jpeg" );
  79. header("Cache-Control:");
  80. header("Pragma:");
  81. header("Set-Cookie:");
  82. ImageJPEG( $image, '', 90 );
  83. ImageDestroy( $image );
  84. die();
  85. }
  86. ?>