PHP development message board tutorial login function

Login function: Let’s first look at the following html code

    欢迎登录  

欢迎登陆后台管理系统

用户名:

密 码:

The form is submitted to main.php. Now let’s analyze main.php

After we log in, if we have a lot of There is no web page to operate on for a long period of time. When you operate again, you need to log in. This will use our session knowledge

First we need to open the session

session_start();

Then we need to introduce the file conn.php that links to the database.

require_once('conn.php');

Get the form information, and then save the form information Enter session

$name = $_POST['username'];
$pwd = md5($_POST['password']);
$_SESSION['name']=$name;
$_SESSION['pwd']=$pwd;

Let’s go to the database to query. If there is information submitted by the form in the database, then we should make the information submitted by the form available for login operations

$sql = "select * from user where username='$name' and password='$pwd'";
$info = mysql_query($sql);
$row = mysql_fetch_row($info );

Then judge $row, if it exists, the login is successful, jump to the homepage to add a message, otherwise, return to the page and log in again

if($row) {
echo " alert('Login failed')";
echo ""; //Login failed, jump to another one Page
}

main.php The complete code is as follows:
alert('登录成功');location.href='message.php';"; }else{ echo ""; echo ""; //登录失败,跳转到另外一个页面 } ?>

Continuing Learning
||
欢迎登录

欢迎登陆后台管理系统

用户名:

密 码:

submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!