下面是生成驗證碼代碼,結果編程之家本站測試過,沒錯誤貼上來的。如果有什麼不懂的地方可以回復,編程之家會為你解釋不了解之處。希望能對你有所收獲。
- <?php
- session_start();
- $nums = rand(1000,9999);
- $_SESSION[nums]=$nums;
- $imgs = ImageCreatetruecolor(100, 35);
- $one = Imagecolorallocate($imgs, 0, 0, 0);
- $two = Imagecolorallocate($imgs, rand(0, 255), rand(0, 255), rand(0, 255));
- $thr = Imagecolorallocate($imgs, rand(50, 200), rand(100, 255), rand(150, 255));
- Imagestring($imgs, 6, rand(5, 60), rand(3, 18), $nums, $two);
- for ($i = 1; $i <= 3; $i ) {
- imageline($imgs, rand(0, 0), rand(0, 25), rand(70, 100), rand(0, 25), $thr);
- }
- for ($i = 1; $i <= 200; $i ) {
- imagesetpixel($imgs,rand()0,rand()5,$two);
- }
- Header("Content-type:image/jpeg");
- imagejpeg($imgs);
- ?>