We are now in the site registration and other places often see you need to enter a verification code, it is the random numbers or symbols in the form of a picture in front of the user, and provide verification before using the relevant features. 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 ',
- Ten = > ' A ',
- One = > ' B ',
- A = > ' C ',
- - = > ' d ',
- - = > ' E ',
- the = > ' F ',
- - = > ' G ',
- - = > ' h ',
- - = > ' i ',
- + = > ' J ',
- - = > ' K ',
- + = > ' l ',
- A = > ' m ',
- at = > ' n ',
- - = > ' O ',
- - = > ' P ',
- - = > ' Q ',
- - = > ' R ',
- - = > ' s ',
- in = > ' t ',
- - = > ' u ',
- to = > ' V ',
- + = > ' W ',
- - = > ' x ',
- the = > ' y ',
- * = > ' z ',
- $ = > ' 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 = New Rndnum ();
- $ Num = $rndnum- > Rnd ();
- Echo $num;
- */
- ?>
Generate a picture of PHP graphics verification Code, fill the random number into the inside:
- php
- Header ("Content-type:image/png");
- Require_once ("rndnum.php");
- $ Rndnum = New Rndnum ();
- $ Authnum = $rndnum- > Rnd ();
- Session_Start ();
- $_session["Extrra_code"]= $authnum;
- $ im = imagecreate (72,20);
- $ Black = imagecolorallocate ($im, 0,0,0);
- $ White = imagecolorallocate ($im, 255,255,255);
- $ Gray = imagecolorallocate ($im, 200,200,200);
- Imagefill ($im, 0,0, $gray);
- Imagestring ($im, 5,10,3, $authnum, $black);
- For ($i=0; $i<$i + + )//Add interfering 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 of all PHP graphics verification Code, I hope to help you.
http://www.bkjia.com/PHPjc/446423.html www.bkjia.com true http://www.bkjia.com/PHPjc/446423.html techarticle we are now in the site registration and other places often meet to require you to enter a verification code, it is to be random numbers or symbols in the form of a picture in front of the user, and provide verification before ...