Advertisement
Guest User

Simple php captcha

a guest
Apr 3rd, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. /* CAPTCHA FILE */
  2. session_start();
  3.  
  4. $_SESSION["rand"] = substr(str_shuffle("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz"), 0, 6);
  5.  
  6. $im = imagecreatetruecolor(62, 25);
  7. $bg = imagecolorallocate($im, 0, 140, 186);
  8. $fg = imagecolorallocate($im, 124, 119, 117);
  9.  
  10. imagefill($im, 0, 0, $bg);
  11. imagestring($im, 5, 5, 5,  $_SESSION["rand"], $fg);
  12.  
  13. header("Cache-Control: no-cache, must-revalidate");
  14. header('Content-type: image/png');
  15.  
  16. imagepng($im);
  17. imagedestroy($im);
  18.  
  19. /* CAPTCHA FILE END */
  20.  
  21. /* FORM FILE */
  22.  
  23. session_start();
  24.  
  25. // some code ...
  26.  
  27. if(isset($_POST["captcha"]) && !empty($_POST["captcha"]) && !is_array($_POST["captcha"]))
  28.     return $_POST["captcha"] == $_SESSION["rand"] ? true : false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement