Php logon and logout instance code. Pm_user is a data table that has not been created. you can create a table on your own. The following describes only the program code for logging on with php and then logging out, for more information, see pm_user. we have not created a table in the data table. you can create a table on your own. next we will only introduce the program code for logging on with php and then logging out, if you need it, you can refer to it.
Login.htm
The code is as follows: |
|
Untitled Document
|
Login. php
The code is as follows: |
|
Function showPage () // determine whether to log on without logon. directly jump to the logon page. { If (! Isset ($ _ SESSION ["user"]) &! Isset ($ _ SESSION ["pwd"]) { If (isset ($ _ COOKIE ["user"]) & isset ($ _ COOKIE ["pwd"]) { $ SQL = "select * from pm_user where u_user = '$ _ COOKIE [user]'"; $ Query = mysql_query ($ SQL ); $ IsUser = is_array ($ row = mysql_fetch_array ($ query); // judge the user name $ IsPwd = $ isUser? $ Row ["u_pwd"] === _ COOKIE ["pwd"]: false; // Determine the password If ($ isPwd) { $ _ SESSION ["user"] = $ _ COOKIE ["user"]; $ _ SESSION ["pwd"] = $ _ COOKIE ["pwd"]; $ _ SESSION ["id"] = $ _ COOKIE ["id"]; $ _ SESSION ["name"] = $ _ COOKIE ["name"]; } } } If (! Isset ($ _ SESSION ["user"]) &! Isset ($ _ SESSION ["pwd"]) { Echo 'script alert ("You haven't logged on! Returning to the login page... "); location. href =" index. php "; script '; Exit (); } } |
Log out
Out. php
The code is as follows: |
|
Function loginOut () // logout function { If (isset ($ _ GET ["login"]) = 'out ') { $ _ SESSION ["user"] = ''; $ _ SESSION ["pwd"] = ''; $ _ SESSION ["id"] = ''; $ _ SESSION ["name"] = ''; Session_destroy (); Echo 'script alert ("exited successfully! "); Location. href =" index. php "; script '; } } |
...