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

PHP login registration registration

In the previous course, we will go to the registration page and jump to reg.php

2.png

Submit the form to the regin.php file

Let’s do it next Take a look at the registration steps

  1. Connect to the database

  2. Get the form information

  3. Judgment Whether the form is empty

  4. Write sql statement and add content to the database

  5. Judge whether the registration is successful

Note: What we need to pay attention to here is the third step. When the database contains the information submitted by the form, the registration should not be successful at this time. To put it more simply, for example, Zhang San has already registered. When you use the username Zhang San, we should give the information that the username has been registered

Let’s explain it in detail below. Let’s take a look at the flow chart first:

regs.png

Connecting to the database is the same as the registration page. Introduce our conn.php file to

get the form information. We can do some filtering operations, such as removing spaces. trim() function To encrypt the password, use md5()

Code to go to:

$name=trim($_POST['username']);

$ password=$_POST['password'];

trim function, filter spaces, if not, we add a lot of spaces after the user name, submit the form, open the firebug debugging tool, we can see the entered user name There will be a lot of spaces at the end. Using the trim function, we can filter out the spaces in the form.

As shown in the figure below

9.png

The trim() function is not used After submission, we can see that there are a lot of spaces.

10.png

The effect after use is as follows

11.png

After md5() encrypted output You will see a 32-bit cipher text

12.png

##Username Zhang San, password 123456, click to register

13.png

The appearance of such ciphertext will have a certain effect on the security of our account

Next we need to determine whether the user name has been registered


First obtain the form information, and then go Query whether it exists in the database table

The code is as follows

$sql = "select * from user where username='$name'";
$info = mysql_query($sql);
$res = mysql_num_rows($info);

Then judge $res. If it exists, it will prompt the user to have been registered and jump to the registration page

If not, perform the registration operation

Before doing the registration operation, we also need to judge the form Is the information empty? If it is empty, it will return to the registration page and give a prompt message.

The code is as follows:

if(empty($name)){
echo "<script> ;alert('Username cannot be empty');location.href='reg.php';</script>";
}else if(empty($password)){
?echo "< script>alert('Password cannot be empty');location.href='reg.php';</script>";
}else{

//Registration operation

}

The registration operation code is as follows:

???????? $sql1?="insert into user(username,password) values('".$name."','"?.$password ."')";
$result = mysql_query($sql1);
if($result){
echo "<script>alert('Registration successful')</script>";
} Else {
echo "& lt; script & gt; alert ('register failure') & lt;/script & gt;";
}

## The complete source code is as follows:

<?php
    require_once("conn.php");//首先鏈接數(shù)據(jù)庫
    $name=trim($_POST['username']);
    //trim函數(shù),過濾空格,如果不加,我們在用戶名后面添加很多空格,提交表單,打開firebug
    //調(diào)試工具,我們可以到輸入的用戶名后面會有很多空格,使用trim函數(shù),我們可以把表單中空格給過濾掉
    $password=$_POST['password'];

       $sql = "select * from user where username='$name'";
        $info = mysql_query($sql);
        $res = mysql_num_rows($info);

    if(empty($name)){
        echo "<script>alert('用戶名不能為空');location.href='reg.php';</script>";
    }else if(empty($password)){
        echo "<script>alert('密碼不能為空');location.href='reg.php';</script>";
    }else{    
        if($res){
            echo "<script>alert('用戶名已存在');location.href='reg.php';</script>";
        }else{
            $sql1 ="insert into user(username,password) values('".$name."','" .md5($password)."')";
            $result = mysql_query($sql1);
            if($result){
                     echo "<script>alert('注冊成功')</script>";
            }else{
                     echo "<script>alert('注冊失敗')</script>";
            }
        }
}    
?>

## In this way, we have completed a simple login and registration. Let's create a few files and copy the code locally to test it


Continuing Learning
||
<?php require_once("conn.php");//首先鏈接數(shù)據(jù)庫 $name=trim($_POST['username']); //trim函數(shù),過濾空格,如果不加,我們在用戶名后面添加很多空格,提交表單,打開firebug //調(diào)試工具,我們可以到輸入的用戶名后面會有很多空格,使用trim函數(shù),我們可以把表單中空格給過濾掉 $password=$_POST['password']; $sql = "select * from user where username='$name'"; $info = mysql_query($sql); $res = mysql_num_rows($info); if(empty($name)){ echo "<script>alert('用戶名不能為空');location.href='reg.php';</script>"; }else if(empty($password)){ echo "<script>alert('密碼不能為空');location.href='reg.php';</script>"; }else{ if($res){ echo "<script>alert('用戶名已存在');location.href='reg.php';</script>"; }else{ $sql1 ="insert into user(username,password) values('".$name."','" .md5($password)."')"; $result = mysql_query($sql1); if($result){ echo "<script>alert('注冊成功')</script>"; }else{ echo "<script>alert('注冊失敗')</script>"; } } } ?>
submitReset Code