Guest User

Untitled

a guest
Jul 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. // Test page one: Create image + Session
  2. session_start();
  3. function randomString() {
  4.     $string = "abcdefghijklmnopqrstuvxyz1234567890";
  5.  
  6.     $final = "";
  7.     for($i=0;$i<=7;$i++) {
  8.         $number = rand(1, 35);
  9.         $getString = substr($string, $number, 1);
  10.         $final .= $getString;
  11. }
  12.  
  13.     return $final;
  14. }
  15.  
  16. $_SESSION['CaptchaImage'] = randomString();
  17. $CaptchaImage = $_SESSION['CaptchaImage'];
  18.  
  19. function createImage($randomString) {
  20.     header ('Content-Type: image/png');
  21.     $getImage = imagecreatetruecolor(80,20);
  22.         $colorBackground = imagecolorallocate($getImage, 0, 0, 0);
  23.         $colorString = imagecolorallocate($getImage, 125, 125, 125);
  24.         $fontImage = imagestring($getImage, 2, 5, 5, $randomString, $colorString);
  25.     $showImage = imagepng($getImage);
  26.     $showImage = imagedestroy($getImage);
  27.  
  28.     return $showImage;
  29. }
  30. createImage($CaptchaImage);
  31.  
  32.  
  33. // Test page two: Show and test image
  34.  
  35. session_start();
  36.  
  37. if($_GET['do'] == "") {
  38.     echo "<img src='sites/test.php'>";
  39. } else {
  40.  
  41. if($_GET['do'] == $_SESSION['CaptchaImage']) {
  42.     echo "The Captcha is correct!";
  43. } else {
  44.     echo "The Captcha is incorrect!";
  45. }
  46. }
Add Comment
Please, Sign In to add comment