Network Verification Code automatic generation program, where there? How do I join PHP?
Reply to discussion (solution)
Just use Google's bar.
https://developers.google.com/recaptcha/
On the internet is more, search it is.
Just use Google's bar.
https://developers.google.com/recaptcha/
Is it possible to call Google's API?
Yes, call Google's API, this factor of safety is still quite high.
Class Captcha {
//
Private $captcha _key = ' captcha_code '; the subscript of the element within the//session
private $width;//width of picture
private $height;//Picture of the high
/**
* Construction Method
* @param $width integer width
* @param $height integer height
*/
Public Function __construct () {
}
Public function Generate ($width, $height) {
Initialize Properties
$this->width = $width;
$this->height = $height;
Make Verification Code
$chars = Array_merge (range (' A ', ' Z '), Range (' A ', ' Z '), Range (' 1 ', ' 9 '));
$rand _keys = Array_rand ($chars, 4);
Shuffle ($rand _keys);
foreach ($rand _keys as $key) {
$char [] = $chars [$key];
}
Add to Session
@session_start ();
Concatenate the strings and save them in the session.
Implode (), which indicates a null character connection if the first argument is not written.
$_session[$this->captcha_key] = implode ($char);
Working with pictures
Step1
$img = Imagecreatetruecolor ($this->width, $this->height);
Step2
Fill background
First design the color, assign to the picture
$backgroud _color = imagecolorallocate ($img, Mt_rand (255), Mt_rand (in. 255), Mt_rand (180, 255));
Fill in the picture
Imagefill ($img, 0, 0, $backgroud _color);
Add some interfering segments
Assign segment Color First
for ($i =0; $i <5; $i + +) {
$line _color = imagecolorallocate ($img, Mt_rand (Mt_rand), Mt_rand (150, 200));
Draw Line
Imageline ($img, Mt_rand (0, $this->width-1), Mt_rand (0, $this->height-1), Mt_rand (0, $this->width-1), Mt_rand (0, $this->height-1), $line _color);
}
Increase interference pixels
for ($i = 0; $i <100; $i + +) {
$pixel _color = imagecolorallocate ($img, Mt_rand (Mt_rand), Mt_rand (150, 200));
Imagesetpixel ($img, Mt_rand (0, $this->width-1), Mt_rand (0, $this->height-1), $pixel _color);
}
Get the colors you can use on your resources first
$string _color = imagecolorallocate ($img, Mt_rand, Mt_rand, Mt_rand (80, 150));//
Writes the obtained string to the picture
Imagestring ($img, 5, 2, $_session[$this->captcha_key], $string _color);
Step3
Set the response header, we want to output to the browser content is a PNG format picture
Header (' content-type:image/png ');
Imagepng ($img);//If there is no second argument, it means the output.
Step 4
Imagedestroy ($IMG);
}
/**
* Determine if the verification code submitted by the user is correct
* @param data submitted by a $code string user
* @return BOOL is consistent returns true inconsistent returns false
*/
Public Function Checkcaptcha ($code) {
Return Strtoupper ($code) = = Strtoupper ($_session[$this->captcha_key]);
}
}
Specifically how to use, you can download online to see Hanshunping video tutorial 120th speak session④-captcha anti-malware attack. The above code is down from its lecture notes.
Class Captcha {
//
Private $captcha _key = ' captcha_code '; the subscript of the element within the//session
private $width;//width of picture
private $height;//Picture of the high
/**
* Construction Method
* @param $width integer width
* @param $height integer height
*/
Public Function __construct () {
}
Public function Generate ($width, $height) {
Initialize Properties
$this->width = $width;
$this->height = $height;
Make Verification Code
$chars = Array_merge (range (' A ', ' Z '), Range (' A ', ' Z '), Range (' 1 ', ' 9 '));
$rand _keys = Array_rand ($chars, 4);
Shuffle ($rand _keys);
foreach ($rand _keys as $key) {
$char [] = $chars [$key];
}
Add to Session
@session_start ();
Concatenate the strings and save them in the session.
Implode (), which indicates a null character connection if the first argument is not written.
$_session[$this->captcha_key] = implode ($char);
Working with pictures
Step1
$img = Imagecreatetruecolor ($this->width, $this->height);
Step2
Fill background
First design the color, assign to the picture
$backgroud _color = imagecolorallocate ($img, Mt_rand (255), Mt_rand (in. 255), Mt_rand (180, 255));
Fill in the picture
Imagefill ($img, 0, 0, $backgroud _color);
Add some interfering segments
Assign segment Color First
for ($i =0; $i <5; $i + +) {
$line _color = imagecolorallocate ($img, Mt_rand (Mt_rand), Mt_rand (150, 200));
Draw Line
Imageline ($img, Mt_rand (0, $this->width-1), Mt_rand (0, $this->height-1), Mt_rand (0, $this->width-1), Mt_rand (0, $this->height-1), $line _color);
}
Increase interference pixels
for ($i = 0; $i <100; $i + +) {
$pixel _color = imagecolorallocate ($img, Mt_rand (Mt_rand), Mt_rand (150, 200));
Imagesetpixel ($img, Mt_rand (0, $this->width-1), Mt_rand (0, $this->height-1), $pixel _color);
}
Get the colors you can use on your resources first
$string _color = imagecolorallocate ($img, Mt_rand, Mt_rand, Mt_rand (80, 150));//
Writes the obtained string to the picture
Imagestring ($img, 5, 2, $_session[$this->captcha_key], $string _color);
Step3
Set the response header, we want to output to the browser content is a PNG format picture
Header (' content-type:image/png ');
Imagepng ($img);//If there is no second argument, it means the output.
Step 4
Imagedestroy ($IMG);
}
/**
* Determine if the verification code submitted by the user is correct
* @param data submitted by a $code string user
* @return BOOL is consistent returns true inconsistent returns false
*/
Public Function Checkcaptcha ($code) {
Return Strtoupper ($code) = = Strtoupper ($_session[$this->captcha_key]);
}
}
Specifically how to use, you can download online to see Hanshunping video tutorial 120th speak session④-captcha anti-malware attack. The above code is down from its lecture notes.
Q: What do I do if I want to generate Google-like code?