PHP instance verification code
As we all know, verification codes are essential for website registration, logon, and many times. Without the verification code, the security of the website is greatly threatened. Therefore, the verification code is an indispensable function in the website development process. The effect of the verification code directly affects the security of the website. (Here, the blogger also spoke about it by the way. the verification code function is really cool, and I will lose a verification code if I can't move it. it looks so upset. Some time ago, 12306 also issued a dynamic verification code. Nima I want to say that no one in the dormitory can enter the correct one. I just want to quickly develop an alternative function and end this function. I think few users prefer to view the verification code all day ). Okay, no more nonsense.
First, use the mind map to clarify the overall thinking:
In auth. in php, the GD library is used for drawing, setting the verification code background, adding randomly generated strings to the background, and saving the strings to the session to ensure that the verification code can be extracted on any page. In form.html, write a simple login form, with the focus on the verification code link. load the verification code in auth. php with the tag. Submit the data to the submit. php page. In submit.php, first-in-line verification code verification (here we will not discuss usernameand passwordverification, to see if the strings in sessionare the same as the ones in the verification code submitted by form.html. Before that, all strings are converted to lowercase. If the strings are the same, the page is redirected. If they are different, the logon page is returned.
1. auth. php
(1) there cannot be any output in front of the header
(2) You must enable the session before using the session.
2.form.html
Login User logon page
(1) method submission method is post
(2) try to ensure coordination between the text box and verification code
3. submit. php
(1) use strtolower () to convert all strings to lowercase, saving the trouble of case-sensitive verification code.
(2) use the if statement to determine whether the two strings are equal to true.
(3) add javascript in it. add the address to jump in the quotation marks of script location = ''script to directly jump. Of course, you can also use header (), but there is no output before header (), which is too limited. It is better to use js.