Here we introduce the production of image verification code, the character verification code can refer to the following articles:
Click to open link
The production of the picture verification code is divided into three steps:
1. Make a picture library
2. Randomly select a picture
3. Output image Content
The code is as follows (here in order to facilitate my direct use of the local image, in fact there will be a lot of pictures, the path is stored in the database):
<?phpsession_start (); $data = Array (dirname (__file__). ' \pics\pic0.jpg ' = ' dog ', DirName (__file__). ' \pics\pic1.jpg ' = ' cat ', DirName (__file__). ' \pics\pic2.jpg ' = ' fish ', dirname (__file__). ' \pics\pic3.jpg ' = ' pig ', dirname (__file__). ' \pics\pic4.jpg ' = ' ma ', dirname (__file__). ' \pics\pic5.jpg ' = ' donkey ', DirName (__file__). ' \pics\pic6.jpg ' = ' bird ', dirname (__file__). ' \pics\pic7.jpg ' = ' chicken ', dirname (__file__). ' \pics\pic8.jpg ' = ' duck ', dirname (__file__). ' \pics\pic9.jpg ' + ' like ', ' $rnd = rand (0,9); $img = DirName (__file__). ' \pics\pic '. $rnd. jpg '; $_session[' authcode ') = $data [$img]; $content = file_get_contents ($img); Header ("Content-type : Image/png "); Echo $content;
Client:
<?phpif (Isset ($_request[' Authcode ')) {session_start (); if ($_request[' authcode ') = = $_session[' Authcode ']) { Echo ' <font color= "#0000cc" > Input correct </font> ';} Else{echo ' <font color= "#cc0000" ><b> input error </b></font> ';} Exit ();}? ><! DOCTYPE html>
Result diagram:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
PHP Verification code--image