Here we have pm_user, which is a data table without creating tables. You can create a table by yourself. Next we will only introduce the program code for logging on with php and then logging out. If you need it, please refer to it.
Login.htm
The Code is as follows: |
Copy code |
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <Html xmlns = "http://www.w3.org/1999/xhtml"> <Head> <Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/> <Title> untitled document </title> </Head> <Body> <Form id = "form1" name = "form1" method = "post" action = ""> <P> <Label for = "user"> </label> <Input type = "text" name = "user" id = "user"/> </P> <P> <Label for = "pwd"> </label> <Input type = "text" name = "pwd" id = "pwd"/> </P> <P> <Input type = "submit" name = "button" id = "button" value = "submit"/> </P> </Form> </Body> </Html> |
Login. php
The Code is as follows: |
Copy code |
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 have not logged on! Returning to the login page... "); location. href =" index. php "; </script> '; Exit (); } } |
Log out
Out. php
The Code is as follows: |
Copy code |
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> '; } } |