User login system (no database)
Key code:
LoginUI. php mainly includes:
---------------------------
The code is as follows: |
Copy code |
<? Php If (error! = Null ){ $ Error = $ _ GET ['error']; Echo $ error; Echo "login failed. Please check your username (yugaga) and password (123456 )"; } ?>
|
----------------------------
Some prompts are displayed after the logon fails.
In loginCheck. php
-----------------------------
The code is as follows: |
Copy code |
<? Php $ Username = $ _ POST ['username']; $ Password = $ _ POST ['password']; If ($ username = "yugaga" & $ password = "123456 & Prime ;){ $ Host = $ _ SERVER ['http _ host']; $ Uri = rtrim (dirname ($ _ SERVER ['php _ SELF ']),'/'); $ Extra = 'Welcome. php? User = '. $ username; Header ("Location: http: // $ host $ uri/$ extra"); } Else { $ Host = $ _ SERVER ['http _ host']; $ Uri = rtrim (dirname ($ _ SERVER ['php _ SELF ']),'/'); $ Extra = 'loginui. php? Error = failer '; Header ("Location: http: // $ host $ uri/$ extra"); } ?>
|
------------------------------------
It mainly verifies the submitted information. Here, regular matching and global variables are used.
Main output information in welcome. php
------------------------------------
The code is as follows: |
Copy code |
<? Php $ Username = $ _ GET ['user']; Echo "welcome". $ username. "login "; ?> |
User logon system (with database)
We tried to connect to the database. Two files are added, one SqlHepler. php, used to obtain the database connection, a userService. php file, used to process user-related operations, such as user login verification. In this session, we just added a function checkUserLogin ($ username, $ password ), determine whether the user has successfully logged on based on the user name and password! ~
Html code
The code is as follows: |
Copy code |
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd"> <Html> <Head> <Title> simple logon demonstration </title> </Head> <Body> <Center> <Form action = "loginCheck. php" method = "post"> User account: <input type = "text" name = "username" size = "20"/> <br/> User secrets: <input type = "password" name = "password" size = "20"/> <br/> <Input type = "submit" value = "submit"/> </Form> <? Php $ Error = $ _ GET ['error']; If ($ error = 'failer '){ Echo "login failed. Please check your username (yugaga) and password (123456 )"; } ?> </Center> </Body> </Html> Main code: ----------------------------------- <? Php Include_once 'sqlhelper. Php '; Function checkUserLogin ($ username, $ password ){ $ Res = mysql_query ("select * from users where username = '". $ username ."'"); If ($ listuser = mysql_fetch_array ($ res ))! = Null ){ If ($ listuser [2] ==$ password ){ Return true; } } Else { Return false; } } ?> ------------------------------------- SqlHelper code: ------------------------------------ <? Php $ Server = "localhost "; $ User = "root "; $ Pass = ""; $ Con = mysql_connect ($ server, $ user, $ pass ); Mysql_select_db ("login", $ con ); ?> ---------------- Code after successful login
<? Php $ Username = $ _ GET ['user']; Echo "welcome". $ username. "login "; ?> |