Today, I have nothing to do with it. 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
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. well, let's not talk much about it. let's look at the Code First:
-
-
Their names are myname and mypass, respectively. now we have a simple js client for better user experience:
-
-
- Script
The function of this function is to determine whether the user has entered a valid user name and password. The most important thing is how to deal with 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! ','');
- }
- ?>