Home > Backend Development > PHP Tutorial > php user login_PHP tutorial

php user login_PHP tutorial

WBOY
Release: 2016-07-13 16:58:37
Original
1081 people have browsed it

keys:php user login php multi-user mall php login php user registration php user manual php online user php multi-user blog php multi-user blog system php simulated login php multi-user mall system

I have nothing to do today, so I will post the PHP user login code of the blog system I wrote to share with you. Let’s take a look at the principle first. The principle is very simple, that is, the user enters the username and password and then uses the PHP file Determine whether it exists in the database. If it exists, save the user name-related information into the session. This is just the simplest and most common method. Okay, without further ado, let’s take a look at the renderings first:

This is a rendering of the login page, other login aliases and passwords

Their names are myname and mypass respectively. Well, in order to make the user experience better, let’s make a simple js client effect:

The function of this function is to determine whether the user input is a legal username and password. I won’t go into details here. The most important thing is how to handle the PHP code.

session_start();//This must be declared. Here is a tip: there cannot be any output before the session. There will be problems in versions below php.5.

$myname =get_value('myname',post);
$mypass =get_value('mypass',post);
if(!preg_match("/^w+$/",$myname) || strlen($myname)<3 || strlen($myname)>15 ){
alert('The entered username information is incorrect! The username must be composed of numbers and underscores and English letters, and the length is 3-15 characters!','');
}
if(!preg_match("/^w+$/",$mypass) || strlen($mypass)<6 || strlen($mypass)>15 ){
alert('Enter the user password! The password must be composed of numbers and underscores, English letters, and the length is 6-15 characters!','');
}
$sql ="select * from tbn where admin_name='$myname' and admin_pwd='".md5($mypass)."'";
$result =mysql_query($sql);
if(mysql_num_rows($result) ){
$my =mysql_fetch_array($result);
$_SESSION['uid']=$myname;
//$_SESSION['auth']=return_auth($my['group_id']); //This is because the user group is used to obtain the permissions of the user group
header("location:main.php");
}else{
alert('Tip: The username and password you entered are inconsistent!','');
}

?>

Note: When reprinting original files, please indicate: www.111cn.cn

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631378.htmlTechArticlekeys: php user login php multi-user mall php login php user registration php user manual php online user php multi-user blog php multi-user blog system php simulates login to php multi-user mall...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template