Subdomain Posts
PHP | 3 days ago
PHP | 160 days ago
PHP | 162 days ago
PHP | 197 days ago
PHP | 209 days ago
PHP | 250 days ago
PHP | 432 days ago
PHP | 478 days ago
PHP | 568 days ago
PHP | 568 days ago
Recent Posts
Python | 5 sec ago
None | 27 sec ago
None | 43 sec ago
None | 1 min ago
None | 2 min ago
None | 2 min ago
C++ | 2 min ago
None | 2 min ago
None | 2 min ago
None | 2 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By Sam Yong on the 14th of Jul 2009 08:07:52 AM Download | Raw | Embed | Report
  1. <?php
  2.  
  3. // note that $_GET['k'] is a static key that you can enter when getting the image.
  4. // generate the key and store into session
  5. $_SESSION['captchasecurity'] = md5(mt_rand().time().$session_hash).$session_hash.md5($_GET['k'].mt_rand());
  6. // create a shorter key for display
  7. $key = dechex(crc32($_SESSION['captchasecurity']));
  8.  
  9. // disable the client side caching
  10. header('Content-type: image/png');
  11. header('Cache-Control: max-age=0');
  12. header('Expires: '.gmdate('r',time()-3600*24*365));
  13. header('Pragma:');
  14.  
  15. // randomize the background image
  16. $r = mt_rand(0,3);
  17. $captcha = imagecreatefrompng('img/captcha'.$r.'.png');
  18.  
  19. $cl = mt_rand(0,50);
  20. $c = imagecolorallocate($captcha, $cl, $cl, $cl);
  21. $line = imagecolorallocate($captcha,233,239,239);
  22.  
  23. $txtx = imagefontwidth(5) * strlen($key) +10;
  24. $txty = imagefontheight(5);
  25.  
  26. $timg1 = imagecreate($txtx,$txtx);
  27. $ba = imagecolorallocatealpha($timg1,0, 0, 0,127);
  28. imagefilledrectangle($timg1, 0, 0, $txtx, $txtx, $ba);
  29. imagesavealpha($timg1, true);
  30.  
  31. $tc = imagecolorallocate($timg1, $cl, $cl, $cl);
  32. imagestring($timg1, 5, 0, $txtx/2 - $txty/2, $key, $tc);
  33.  
  34. $tca = imagecolorallocatealpha($timg1, 255, 255, 255,127);
  35. $timg = imagerotate($timg1, mt_rand(-5,5), $tca);
  36. imagesavealpha($timg, true);
  37. imagecopy($captcha, $timg, mt_rand(2,22), mt_rand(3,6), 0, $txtx/2 - $txty/2, $txtx, $txtx);
  38.  
  39. // output the captcha image
  40. imagepng($captcha);
  41.  
  42. // free up memory
  43. imagedestroy($timg);imagedestroy($timg1);
  44. imagedestroy($captcha);
  45. ?>
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: