Php verification code how to kneel down and ask the master to add my qq7798000029, randomly select a number or letter and then display it in the form of an image. 1. assume that you are a login. php page: & lt ;? Php & nbsp; include (& quot; conn. php & quot;) how to get the php verification code
Click here to add my qq7798000029
------ Solution --------------------
Just randomly select numbers or letters and display them as images.
------ Solution --------------------
1. assume that you have a login. php page: under this page,
Include ("conn. php"); // Connect to Mysql.
Session_start ();
Echo $ _ SESSION [check_pic];
If ($ _ POST ){
$ Code = $ _ POST [code];
If ($ code! = $ _ SESSION [check_pic])
Echo "script" alert ('The verification code is incorrect! '); Location. href = 'login. php'; script ";
}
?>
2. src = 'Inc/vCode. php? Tm = '+ Math. inc/vCode in random. php refers to the inc folder in the current directory, which contains a vCode. php, you create a new vCode. php, the code is as follows, you can paste it:
/*
* Put a font. ttc font in the directory.
$ Num characters
$ Size character size
Random color
*/
// VCode ********
Function vCode ($ num = 4, $ size = 20, $ width = 0, $ height = 0 ){
Session_start ();
! $ Width & amp; $ width = $ num * $ size * 4/5 + 5;
! $ Height & $ height = $ size + 10;
// Remove 0 1 O l and so on
$ Str= "23456789 abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVW ";
$ Code = '';
For ($ I = 0; $ I <$ num; $ I ++ ){
$ Code. = $ str [mt_rand (0, strlen ($ str)-1)];
}
$ _ SESSION [check_pic] = $ code;
// Draw an image
$ Im = imagecreatetruecolor ($ width, $ height );
// Define the color to be used
$ Back_color = imagecolorallocate ($ im, 235,236,237 );
$ Boer_color = imagecolorallocate ($ im, 118,151,199 );
$ Text_color = imagecolorallocate ($ im, mt_rand (0,200), mt_rand (0,120), mt_rand (0,120 ));
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service