PHP graphic verification code implementation method. We often see requests for verification codes in website registration and other places. it shows random numbers or symbols in the form of images to users, after verification is provided, we often see the request for verification code in the website registration and other places. it displays random numbers or symbols in the form of images in front of users, and provide verification before using the relevant functions. Today we will introduceThe specific implementation code is as follows:
-
Php
-
- Class rndnum {
-
- Function rnd (){
- Srand (double) microtime () * 1000000 );
- $Rnd_number=Array(
- 1=>'1 ',
- 2=>'2 ',
- 3=>'3 ',
- 4=>'4 ',
- 5=>'5 ',
- 6=>'6 ',
- 7=>'7 ',
- 8=>'8 ',
- 9=>'9 ',
- 10=>'A ',
- 11=>'B ',
- 12=>'C ',
- 13=>'D ',
- 14=>'E ',
- 15=>'F ',
- 16=>'G ',
- 17=>'H ',
- 18=>'I ',
- 19=>'J ',
- 20=>'K ',
- 21=>'L ',
- 22=>'M ',
- 23=>'N ',
- 24=>'O ',
- 25=>'P ',
- 26=>'Q ',
- 27=>'R ',
- 28=>'S ',
- 29=>'T ',
- 30=>'U ',
- 31=>'V ',
- 32=>'W ',
- 33=>'X ',
- 34=>'Y ',
- 35=>'Z ',
- 36=>'0'
- );
- $Result=Array_rand($ Rnd_number, 6 );
- $J=Count($ Result );
- For ($I=0; $ I<$ J; $ I ++ ){
- $Re.= $ Rnd_number [$ result [$ I];
- }
- // $Re= $ Rnd_number [$ result [1]. $ rnd_number [$ result [2]. $ rnd_number [$ result [3]. $ rnd_number [$ result [4]. $ rnd_number [$ result [5]. $ rnd_number [$ result [6]. $ rnd_number [$ result [7];
- // Return array_keys ($ result );
- Return $ re;
- }
- }
- /* Usage
- $Rndnum=NewRndnum ();
- $Num= $ Rndnum->Rnd ();
- Echo $ num;
- */
- ?>
Generate an image of the PHP graphic verification code and fill in the random number:
-
Php
-
- Header ("Content-type: image/PNG ");
- Require_once ("rndnum. php ");
- $Rndnum=NewRndnum ();
- $Authnum= $ Rndnum->Rnd ();
- Session_start ();
- $ _ SESSION ["extrra_code"] = $ authnum;
- $Im=Imagecreate(72, 20 );
- $Black=ImageColorAllocate($ Im, 0, 0 );
- $White=ImageColorAllocate($ Instant, 255,255,255 );
- $Gray=ImageColorAllocate($ Instant, 200,200,200 );
- Imagefill ($ im, 0, 0, $ gray );
- Imagestring ($ im, 5, 10, 3, $ authnum, $ black );
- For ($I=0; $ I<200; $ I ++) // add interference pixels
- {
- $Randcolor=ImageColorallocate($ Im, rand (0,255), rand (0,255), rand (0,255 ));
- Imagesetpixel ($ im, rand () % 70, rand () % 30, $ randcolor );
- }
- ImagePNG ($ im );
- ImageDestroy ($ im );
- ?>
The above is the implementation code of all PHP graphic verification codes. I hope it will help you.
...