vcode.php 640 B

1234567891011121314151617181920
  1. <?php
  2. session_start();
  3. include('../config.php');
  4. $img = imagecreatetruecolor(60, 30);
  5. $black = imagecolorallocate($img, 0x00, 0x00, 0x00);
  6. $green = imagecolorallocate($img, 0x00, 0xFF, 0x00);
  7. $white = imagecolorallocate($img, 0xFF, 0xFF, 0xFF);
  8. imagefill($img, 0, 0, $white);
  9. $code = rand(1000, 9999);
  10. $_SESSION['vcode'] = md5($code . $VERIFICATION_KEY);
  11. imagestring($img, 5, 8, 8, $code, $black);
  12. for ($i = 0; $i < 100; $i++) {
  13. imagesetpixel($img, rand(0, 60), rand(0, 30), $black);
  14. imagesetpixel($img, rand(0, 60), rand(0, 30), $green);
  15. }
  16. header("content-type: image/png");
  17. imagepng($img);
  18. imagedestroy($img);