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

/wp-content/plugins/si-captcha-for-wordpress/captcha/securimage_show.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 138 lines | 118 code | 14 blank | 6 comment | 38 complexity | f6f1a21eb9dd8d7723282ad764bbfb2f MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0
  1. <?php
  2. if ( isset($_GET['prefix']) && preg_match('/^[a-zA-Z0-9]{15,17}$/',$_GET['prefix']) ){
  3. // no session
  4. $prefix = $_GET['prefix'];
  5. include 'securimage.php';
  6. $char_length = 4;
  7. $chars = 'ABCDEFHKLMNPRSTUVWYZ234578';
  8. $chars_num = '234578'; // do not change this or the code will break!!
  9. // one random position always has to be a number so that a 4 letter swear word could never appear
  10. $rand_pos = mt_rand( 0, $char_length - 1 );
  11. $captcha_word = '';
  12. for ( $i = 0; $i < $char_length; $i++ ) {
  13. // this rand character position is a number only so that a 4 letter swear word could never appear
  14. if($i == $rand_pos) {
  15. $pos = mt_rand( 0, strlen( $chars_num ) - 1 );
  16. $char = $chars_num[$pos];
  17. } else {
  18. $pos = mt_rand( 0, strlen( $chars ) - 1 );
  19. $char = $chars[$pos];
  20. }
  21. $captcha_word .= $char;
  22. }
  23. $img = new securimage();
  24. $img->code_length = 4;
  25. $img->image_width = 175;
  26. $img->image_height = 60;
  27. if(isset($_GET['si_sm_captcha']) && $_GET['si_sm_captcha'] == 1) {
  28. $img->image_width = 132;
  29. $img->image_height = 45;
  30. }
  31. //set some settings
  32. $img->nosession = true;
  33. $img->prefix = $prefix;
  34. $img->captcha_path = getcwd() . '/temp/';
  35. if(file_exists($img->captcha_path . $prefix . '.php') && is_readable( $img->captcha_path . $prefix . '.php' ) ) {
  36. include( $img->captcha_path . $prefix . '.php' );
  37. $img->captcha_word = $captcha_word;
  38. } else {
  39. $img->captcha_word = $captcha_word;
  40. }
  41. $img->use_multi_text = true;
  42. $img->use_transparent_text = true;
  43. $img->text_transparency_percentage = 20;
  44. $img->num_lines = 3;
  45. $img->perturbation = 0.6; // 1.0 = high distortion, higher numbers = more distortion
  46. $img->multi_text_color = array(
  47. '#6666FF','#660000','#3333CC','#993300','#0060CC',
  48. '#339900','#6633CC','#330000','#006666','#CC3366',
  49. );
  50. if (isset($_GET['difficulty']) && $_GET['difficulty'] == 1 ) {
  51. $img->perturbation = 0.5; // 1.0 = high distortion, higher numbers = more distortion
  52. $img->num_lines = 2;
  53. $img->multi_text_color = array('#6666FF','#660000','#3333CC','#993300','#0060CC');
  54. }
  55. if (isset($_GET['difficulty']) && $_GET['difficulty'] == 2 ) {
  56. $img->perturbation = 0.7; // 1.0 = high distortion, higher numbers = more distortion
  57. $img->num_lines = 6;
  58. }
  59. if (isset($_GET['no_trans']) && $_GET['no_trans'] == 1) {
  60. $img->use_transparent_text = false;
  61. }
  62. $img->charset = 'ABCDEFHKLMNPRSTUVWYZ234578';
  63. $img->ttf_file = getcwd() . '/ttffonts/ahg-bold.ttf'; // single font
  64. $img->line_color = new Securimage_Color(rand(0, 64), rand(64, 128), rand(128, 255));
  65. $img->image_type = 'png';
  66. $img->background_directory = getcwd() . '/backgrounds';
  67. $img->ttf_font_directory = getcwd() . '/ttffonts';
  68. $img->show('');
  69. if(!file_exists($img->captcha_path . $prefix . '.php')) {
  70. if ( $fh = fopen( $img->captcha_path . $prefix . '.php', 'w' ) ) {
  71. fwrite( $fh, '<?php $captcha_word = \'' . $captcha_word . '\'; ?>' );
  72. fclose( $fh );
  73. @chmod( $img->captcha_path . $prefix . '.php', 0755 );
  74. }
  75. }
  76. unset($img);
  77. exit;
  78. } else {
  79. // session
  80. include 'securimage.php';
  81. $img = new securimage();
  82. $img->code_length = 4;
  83. $img->image_width = 175;
  84. $img->image_height = 60;
  85. if(isset($_GET['si_sm_captcha']) && $_GET['si_sm_captcha'] == 1) {
  86. $img->image_width = 132;
  87. $img->image_height = 45;
  88. }
  89. //set some settings
  90. if( isset($_GET['si_form_id']) && in_array($_GET['si_form_id'], array('com', 'reg', 'log')) ) {
  91. $img->form_id = $_GET['si_form_id'];
  92. }
  93. $img->use_multi_text = true;
  94. $img->use_transparent_text = true;
  95. $img->text_transparency_percentage = 20;
  96. $img->num_lines = 3;
  97. $img->perturbation = 0.6; // 1.0 = high distortion, higher numbers = more distortion
  98. $img->multi_text_color = array(
  99. '#6666FF','#660000','#3333CC','#993300','#0060CC',
  100. '#339900','#6633CC','#330000','#006666','#CC3366',
  101. );
  102. if (isset($_GET['difficulty']) && $_GET['difficulty'] == 1 ) {
  103. $img->perturbation = 0.5; // 1.0 = high distortion, higher numbers = more distortion
  104. $img->num_lines = 2;
  105. $img->multi_text_color = array('#6666FF','#660000','#3333CC','#993300','#0060CC');
  106. }
  107. if (isset($_GET['difficulty']) && $_GET['difficulty'] == 2 ) {
  108. $img->perturbation = 0.7; // 1.0 = high distortion, higher numbers = more distortion
  109. $img->num_lines = 6;
  110. }
  111. if (isset($_GET['no_trans']) && $_GET['no_trans'] == 1) {
  112. $img->use_transparent_text = false;
  113. }
  114. $img->charset = 'ABCDEFHKLMNPRSTUVWYZ234578';
  115. $img->ttf_file = getcwd() . '/ttffonts/ahg-bold.ttf'; // single font
  116. $img->line_color = new Securimage_Color(rand(0, 64), rand(64, 128), rand(128, 255));
  117. $img->image_type = 'png';
  118. $img->background_directory = getcwd() . '/backgrounds';
  119. $img->ttf_font_directory = getcwd() . '/ttffonts';
  120. $img->show('');
  121. unset($img);
  122. exit;
  123. }
  124. ?>