亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Make a simple verification code

What is a verification code?

Verification code is to generate a picture from a string of randomly generated numbers or symbols, with some interfering pixels added to the picture (to prevent OCR), and the verification code is visually recognized by the user. Code information, enter the form and submit for website verification. A certain function can only be used after successful verification.

The function of the verification code:

Effectively prevent a hacker from continuously logging in to a specific registered user using a specific program to brute force try. In fact, modern verification codes generally prevent machines from registering in batches and preventing machines from posting replies in batches. Currently, many websites use verification code technology to prevent users from using robots to automatically register, log in, and spam.

What we are mainly talking about here is the random digital picture verification code. The characters on the pictures are relatively regular, some may have some random interferon added, and some have random character colors.

Publish a basic image that generates a png picture verification code:

1. Generate a png picture
2. Set the background color for the picture
3. Set the font color and Style
4. Generate a 4-digit random verification code
5. Adjust the rotation angle and position of each generated character and draw it on the png image
6. Add noise and interference lines to prevent registration machine analysis Original picture to maliciously register
7, output picture
8, release the memory occupied by the picture

The following is an example of PHP verification code code:

<?php
//設(shè)置session,必須處于腳本最頂部
  session_start();
  
  $image = imagecreatetruecolor(100, 30);    //1>設(shè)置驗證碼圖片大小的函數(shù)
  //5>設(shè)置驗證碼顏色 imagecolorallocate(int im, int red, int green, int blue);
  $bgcolor = imagecolorallocate($image,255,255,255); //#ffffff
  //6>區(qū)域填充 int imagefill(int im, int x, int y, int col) (x,y) 所在的區(qū)域著色,col 表示欲涂上的顏色
  imagefill($image, 0, 0, $bgcolor);
  //10>設(shè)置變量
  $captcha_code = "";
  //7>生成隨機數(shù)字
  for($i=0;$i<4;$i++){
    //設(shè)置字體大小
    $fontsize = 6;
    //設(shè)置字體顏色,隨機顏色
    $fontcolor = imagecolorallocate($image, rand(0,120),rand(0,120), rand(0,120));      //0-120深顏色
    //設(shè)置數(shù)字
    $fontcontent = rand(0,9);
    //10>.=連續(xù)定義變量
    $captcha_code .= $fontcontent;
    //設(shè)置坐標
    $x = ($i*100/4)+rand(5,10);
    $y = rand(5,10);
   imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);
  }
  //10>存到session
  $_SESSION['authcode'] = $captcha_code;
  //8>增加干擾元素,設(shè)置雪花點
  for($i=0;$i<200;$i++){
    //設(shè)置點的顏色,50-200顏色比數(shù)字淺,不干擾閱讀
    $pointcolor = imagecolorallocate($image,rand(50,200), rand(50,200), rand(50,200));
    //imagesetpixel — 畫一個單一像素
    imagesetpixel($image, rand(1,99), rand(1,29), $pointcolor);
  }
  //9>增加干擾元素,設(shè)置橫線
  for($i=0;$i<4;$i++){
    //設(shè)置線的顏色
    $linecolor = imagecolorallocate($image,rand(80,220), rand(80,220),rand(80,220));
    //設(shè)置線,兩點一線
    imageline($image,rand(1,99), rand(1,29),rand(1,99), rand(1,29),$linecolor);
  }
  //2>設(shè)置頭部,image/png
  header('Content-Type: image/png');
  //3>imagepng() 建立png圖形函數(shù)
  imagepng($image);
  //4>imagedestroy() 結(jié)束圖形函數(shù) 銷毀$image
  imagedestroy($image);
?>

After using the verification code file, you will get a picture similar to the following:

24.png

Click the verification code picture in the upper left corner, and the 4-digit number obtained will change.

Continuing Learning
||
<?php //設(shè)置session,必須處于腳本最頂部 session_start(); $image = imagecreatetruecolor(100, 30); //1>設(shè)置驗證碼圖片大小的函數(shù) //5>設(shè)置驗證碼顏色 imagecolorallocate(int im, int red, int green, int blue); $bgcolor = imagecolorallocate($image,255,255,255); //#ffffff //6>區(qū)域填充 int imagefill(int im, int x, int y, int col) (x,y) 所在的區(qū)域著色,col 表示欲涂上的顏色 imagefill($image, 0, 0, $bgcolor); //10>設(shè)置變量 $captcha_code = ""; //7>生成隨機數(shù)字 for($i=0;$i<4;$i++){ //設(shè)置字體大小 $fontsize = 6; //設(shè)置字體顏色,隨機顏色 $fontcolor = imagecolorallocate($image, rand(0,120),rand(0,120), rand(0,120)); //0-120深顏色 //設(shè)置數(shù)字 $fontcontent = rand(0,9); //10>.=連續(xù)定義變量 $captcha_code .= $fontcontent; //設(shè)置坐標 $x = ($i*100/4)+rand(5,10); $y = rand(5,10); imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor); } //10>存到session $_SESSION['authcode'] = $captcha_code; //8>增加干擾元素,設(shè)置雪花點 for($i=0;$i<200;$i++){ //設(shè)置點的顏色,50-200顏色比數(shù)字淺,不干擾閱讀 $pointcolor = imagecolorallocate($image,rand(50,200), rand(50,200), rand(50,200)); //imagesetpixel — 畫一個單一像素 imagesetpixel($image, rand(1,99), rand(1,29), $pointcolor); } //9>增加干擾元素,設(shè)置橫線 for($i=0;$i<4;$i++){ //設(shè)置線的顏色 $linecolor = imagecolorallocate($image,rand(80,220), rand(80,220),rand(80,220)); //設(shè)置線,兩點一線 imageline($image,rand(1,99), rand(1,29),rand(1,99), rand(1,29),$linecolor); } //2>設(shè)置頭部,image/png header('Content-Type: image/png'); //3>imagepng() 建立png圖形函數(shù) imagepng($image); //4>imagedestroy() 結(jié)束圖形函數(shù) 銷毀$image imagedestroy($image); ?>
submitReset Code