search
  • Sign In
  • Sign Up
Password reset successful

Follow the proiects vou are interested in andi aet the latestnews about them taster

PHP development verification code mixed letter and number verification code

Mixed letters and numbers verification code

Make the verification code content display a mixture of letters and numbers

<?php
 $image = imagecreatetruecolor(100,30);
 $bgcolor = imagecolorallocate($image,255,255,255);//#FFFFFFFFFFFF
 imagefill($image,0,0,$bgcolor);
 for ($i=0;$i<4;$i++){
     $fontsize = 6;
     $fontcolor = imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));
     $data='abcdefghijklmnopqrstuvwxyz1234567890';
     $fontcontent=substr($data,rand(0,strlen($data)),1);
     $x = ($i * 100/4)+rand(5,10);
     $y = rand(5,10);
     imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);
 }
 for($i=0;$i<200;$i++){
     $pointcolor = imagecolorallocate($image,rand(50,200),rand(50,200),rand(50,200));
     imagesetpixel($image,rand(1,99),rand(1,29),$pointcolor);
 }
 for($i=0;$i<8;$i++){
     $linecolor = imagecolorallocate($image,rand(60,220),rand(60,220),rand(60,220));
     imageline($image,rand(1,99),rand(1,29),rand(1,99),rand(1,29),$linecolor);
 }
 header('content-type: image/png');
 imagepng($image);
 //销毁
 imagedestroy($image);
 ?>

Verification code of letters and numbers The difference is not big, you just need to change the generated numbers into letters and numbers.

for ($i=0;$i<4;$i++){
     $fontsize = 6;
     $fontcolor = imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));
     $data='abcdefghijklmnopqrstuvwxyz1234567890';
     $fontcontent=substr($data,rand(0,strlen($data)),1);
     $x = ($i * 100/4)+rand(5,10);
     $y = rand(5,10);
     imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);
 }

The difference is $data='abcdefghijklmnopqrstuvwxyz1234567890';Define a dictionary

Define the $fontcontent function and intercept the contents in the dictionary The number is displayed immediately.


new file
<?php $image = imagecreatetruecolor(100,30); $bgcolor = imagecolorallocate($image,255,255,255);//#FFFFFFFFFFFF imagefill($image,0,0,$bgcolor); for ($i=0;$i<4;$i++){ $fontsize = 6; $fontcolor = imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120)); $data='abcdefghijklmnopqrstuvwxyz1234567890'; $fontcontent=substr($data,rand(0,strlen($data)),1); $x = ($i * 100/4)+rand(5,10); $y = rand(5,10); imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor); } for($i=0;$i<200;$i++){ $pointcolor = imagecolorallocate($image,rand(50,200),rand(50,200),rand(50,200)); imagesetpixel($image,rand(1,99),rand(1,29),$pointcolor); } for($i=0;$i<8;$i++){ $linecolor = imagecolorallocate($image,rand(60,220),rand(60,220),rand(60,220)); imageline($image,rand(1,99),rand(1,29),rand(1,99),rand(1,29),$linecolor); } header('content-type: image/png'); imagepng($image); //销毁 imagedestroy($image); ?>
Reset Code
Automatic operation
submit
Preview Clear