cafreak

Captcha generator with session!

Apr 23rd, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. <?php
  2. session_start(); //Set Sessions Available To Set & Get
  3. $width = 100; // Width of the Image
  4. $height = 60; //Height of the Image
  5. $textCNG = substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',11)),0,rand(4,7)); //Created random Text
  6. $text = $textCNG; //Set Final Text to Randomized Text
  7. $_SESSION['captcha'] = $text; //Set Session Text
  8. header ("Content-type: image/png"); //Set HTML Header
  9.  
  10. $img = ImageCreate ($width, $height) or die ("Cannot Initialize new GD image stream"); //Create New Image
  11. $background_color = ImageColorAllocate ($img, 255, 255, 255); //Set Background Color
  12. $style_color = ImageColorAllocate ($img, 59, 59, 59); //Set Style Color
  13. $text_color = ImageColorAllocate ($img, 120, 95, 95); //Set Text Color
  14.  
  15. for($i >= 0; $i <= rand(2,5); $i++){
  16.     imageline($img,0,rand()%$height,$width,rand()%$height,$style_color);//Set Random Lines Into The Image
  17. }
  18. for($i >= 0; $i <= rand(220,440); $i++){
  19.     imagesetpixel($img,rand()%$width,rand()%$height,$style_color); //Set Dots Into The Image
  20. }
  21.  
  22. imagestring($img, 5, 22, 22, $text, $text_color); //Write Image Text
  23.  
  24.  
  25. ImagePng ($img); //Show the image
  26.  
  27. imagedestroy($img); //Destroy the image
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment