The principle of user authentication is simple: first, you need to enter the user name and password on the page. Of course, users who are not registered must first register. Then, you can call the database to search for users. If yes, confirm it. If no, the user is reminded to register first. It is easy to use PHP to complete this process, but note that if you want to confirm the user identity in future pages
The principle of user authentication is simple: first, you need to enter the user name and password on the page. Of course, users who are not registered must first register. Then, you can call the database to search for users. If yes, confirm it. If no, the user is reminded to register first. It is easy to use PHP to complete this process, but note that if you want to confirm the user identity in future pages
The principle of user authentication is simple: first, you need to enter the user name and password on the page. Of course, users who are not registered must first register. Then, you can call the database to search for users.
If yes, confirm it. If no, the user is reminded to register first. It is easy to use PHP to complete this process, but it should be noted that if you want to confirm the user identity in future pages, you can only come up with a method to use PHP3. To use the session, you have to wait for the release of the official PHP4 version!
The first step is to create a login page. I will not talk about it here. I just made a simple one, and everyone is doing well.
Step 2: design the validation program after logon.
Login. php: mysql_connect ("localhost", "user", "password")/* connect to the database, modify the user name and password */or die ("unable to connect to the database, please try again "); mysql_select_db (" userinfo ") or die (" You cannot select a database, please try again "); $ today = date (" Y-m-d H: I: s "); $ query =" select id from usertbl where name = $ name and password = $ password/* search for and log on to user information from the database */"; $ result = mysql_query ($ query); $ numrows = mysql_num_rows ($ result); if ($ numrows = 0) {/* verifies whether users with the same data can be found, no, it is not registered */echo illegal user; register echo First; echo retry;} else {$ row = mysql_fetch_array ($ result); $ id = $ row [0]; $ query = "update usertbl set lastlogin = $ today where id = $ id"; $ result = mysql_query ($ query); SetCookie ("usercookie", "Welcome, $ name ");/* cookie is used here to facilitate subsequent page authentication. However, I have not released this part. If you are interested, please confirm that */echo is successfully logged on !; }?> |
The third step is of course the registration page, and I will not talk much about it.
Step 4: confirm the identity after registration and enter the database.
Register. php: mysql_connect ("localhost", "user", "password")/* change the user name and password */or die ("unable to connect to the database, please try again "); mysql_select_db ("userinfo") or die ("You cannot select a database, please try again"); $ query = "select id from usertbl where name = $ name \"; /* search for user information with the same name from the database */$ result = mysql_query ($ query); $ numrows = mysql_num_rows ($ result); if ($ numrows! = 0)/* found. Of course, someone first registered the same name */{echo already registered this name. Please select another name !;} Else {$ query = "insert into usertbl values (0, $ name, $ password ,\)"; /* enter new user information if the same user information cannot be found */mysql_query ($ query); echo registration successful; echo login !;} ?> |
The next step is the use of cookies. I originally intended to use cookies so that every page can identify users. However, since other pages are not ready yet, I do not know what information is needed. So there is only one simple application. Here we use the php reference:
If (! $ Usercookie) {header ("invalid user") ;}?> Welcome. php: require ("cookie. php");/* Call cookie. php */?> Echo $ usercookie;?> |
This completes a very simple user authentication system. Of course, if you want to use it, you have to build a database. below is the structure of my database table. The database name is userinfo.
create table usertbl ( ID int auto_increment primary key, Name varchar(30), Password varchar(20), Lastlogin varchar(20) ); |
(Responsible editor: Ming mingming_ky # 126.com TEL :( 010)-68476636)