Login function (3)

The previous preparations and the login front-end page have been completed. Now we will introduce the login function code.

First create a login.php file to write our login php code.

The first step is to connect to the database first, otherwise the information in the database will not be obtained. The code is as follows :

The second step: Whether it is a user name or a password, we pass the value to the php program through the front-end form, and then verify it, so the next step is to first Only by getting the value passed by the front-end form can we verify whether it is right or wrong. The code to get the value is as follows:

Why do we post instead of get? This requires taking a look at our front-end form and the information in the form tag:

...

action refers to where the information is submitted and how the method is passed. Here we are the post method

Step 3: After we obtain the value, we need to verify whether the value is the same as the value in the database. They must be the same before you can log in. The verification code is as follows:

Step 4: Query the result After that, we will start to verify:

"; echo "返回登陆页面";//如果不一致,将重新跳转至登录页面重新登录 } ?>

It seems like something is missing?

...

...

The verification code seems like Didn’t say...

Finally let’s talk about the verification code.

We need a program to generate verification codes. First, create a PHP file called passcode.php to write and generate verification codes.

Below I will write the detailed way of writing the verification code. Each key and difficult point will be commented, so that you can understand, pay attention, and read the code:

.=连续定义变量 $captcha_code .= $fontcontent; //设置坐标 $x = ($i*100/4)+rand(5,10); $y = rand(5,10); imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor); } //存到session $_SESSION['authcode'] = $captcha_code; //增加干扰元素,设置雪花点 for($i=0;$i<200;$i++){ //设置点的颜色,50-200颜色比数字浅,不干扰阅读 $pointcolor = imagecolorallocate($image,rand(50,200), rand(50,200), rand(50,200)); //imagesetpixel — 画一个单一像素 imagesetpixel($image, rand(1,99), rand(1,29), $pointcolor); } //增加干扰元素,设置横线 for($i=0;$i<4;$i++){ //设置线的颜色 $linecolor = imagecolorallocate($image,rand(80,220), rand(80,220),rand(80,220)); //设置线,两点一线 imageline($image,rand(1,99), rand(1,29),rand(1,99), rand(1,29),$linecolor); } //设置头部,image/png header('Content-Type: image/png'); //imagepng() 建立png图形函数 imagepng($image); //imagedestroy() 结束图形函数 销毁$image imagedestroy($image); ?>

If you want to understand each step in detail. To understand the function of a line of code, you can talk about the code changes (try to be very different from before so that it is obvious), and then see how the changes are different from before. In this way, you will know the function of this line of code.

The next step is to verify the verification code. Look at the code:

Okay, this is our complete login function.

Continuing Learning
||
"; echo "返回登陆页面"; } // 我这里没有数据库,所以右边会显示连接失败。 ?>
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!