Keys: php user login php multi-user mall php login php user registration php user manual php online user php multi-user blog system php simulate login php multi-user mall System
I have nothing to do today. I will post the php user logon code of my own blog system to share with you. Let's take a look at the principle. The principle is very simple, the user enters the user name and password and then uses the PHP file to determine whether the database exists. If the user is saved, the user name information is saved to the session, which is the simplest. it is also a common method. let's take a look at it:
This is a logon page. Other Logon aliases and passwords
<Input name = "myname" type = "text" id = "myname" style = "border: solid 0px;"/>
<Input name = "mypass" type = "password" id = "mypass" style = "border: solid 0px;"/>
Their names are myname and mypass, respectively. Now we have a simple js client for better user experience:
<Script language = "javascript">
<! --
Function check (){
Var myname = document. getElementById ('myname'). value;
Var mypass = document. getElementById ('mypass'). value;
If (! Myname. match (/^ \ w {3, 15}/) | myname. length <3 | myname. length> 15 ){
Alert ('administrator name must consist of letters or group words! ');
Form1.myname. select ();
Return false;
}
If (! Mypass. match (/^ \ w {6, 15}/) | mypass. length <6 | mypass. length> 15 ){
Alert ('the logon password must be a number or English letter, and the password length is 6-15! ');
Form1.mypass. select ();
Return false;
}
}
-->
</Script> the function is used to determine whether the user has entered a valid user name and password. The most important thing is how to handle php code.
<?
Session_start (); // You must declare this and give a small tip: No output can be made before the session. There may be problems in versions earlier than 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 user name entered is incorrect! The username must consist of English letters, numbers, and underlines. It must be 3-15 characters in length! ','');
}
If (! Preg_match ("/^ \ w + $/", $ mypass) | strlen ($ mypass) <6 | strlen ($ mypass)> 15 ){
Alert ('Enter the user password! The password must consist of English letters, numbers, underscores (_) and a length of 6 to 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 ('prompt: the user name and password you entered are inconsistent! ','');
}
?>
Note: For original document reprinting, please note: www.111cn.cn