HtmlheadtitleLogintitlemetahttp-equivContent-Typecontenttexthtml; charsetgb2312headbodyformnameform1methodpostactionlogin. phptablealigncentercellpadding2cellspacing2trtdwidth
HtmlheadtitleLogin/titlemeta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/headbodyform name = "form1" method = "post" action = "login. php "table width =" 300 "border =" 0 "align =" center "cellpadding =" 2 "cellspacing =" 2 "tr td width ="
<Html> <pead> <title> Login </title> <meta http-equiv = "Content-Type" content = "text/html; charset = gb2312 "> </pead> <body> </ptml>
<? Php @ mysql_connect ("localhost", "root", "1981427") // before selecting a database, connect to the database server or die ("database server connection failed "); @ mysql_select_db ("test") // select the database mydbor die ("the database does not exist or is unavailable"); // obtain the user input $ username = $ _ POST ['username']; $ passcode = $ _ POST ['passcode']; $ cookie =$ _ POST ['cooker']; // execute an SQL statement $ query = @ mysql_query ("select username, userflag from users ". "where username = '$ username' and passcode =' $ passcode'") or die ("SQL statement execution failed"); // determine whether the user exists , The password is correct if ($ row = mysql_fetch_array ($ query) {if ($ row ['userflag'] = 1 or $ row ['userflag'] = 0) // determine whether the user permission information is valid {switch ($ cookie) // set the cookie retention time {case 0: // Save the Cookie as the browser process setcookie ("username", $ row ['username']); break; case 1: // save the one-day setcookie ("username ", $ row ['username'], time () + 24*60*60); break; case 2: // save 30-day setcookie ("username ", $ row ['username'], time () + 30*24*60*60); break; case 3: // Save the 365-day setcookie ("use Rname ", $ row ['username'], time () + 365*24*60*60); break;} header (" location: main. php "); // automatically jump to main. php} else {echo "incorrect user permission information" ;}} else {echo "incorrect user name or password" ;}?>
<? Phpsession_start (); if (isset ($ _ COOKIE ['username']) {@ mysql_connect ("localhost", "root", "1981427 ") // before selecting a database, connect to the database server or die ("database server connection failed"); @ mysql_select_db ("test ") // select the database mydbor die ("the database does not exist or is unavailable"); // obtain Session $ username =$ _ COOKIE ['username']; // run the SQL statement to obtain the userflag value $ query = @ mysql_query ("select userflag from users ". "where username = '$ username'") or die ("SQL statement execution failed"); $ row = mysql_fetch_array ($ query); // obtain User Permissions Limited information $ flag = $ row ['userflag']; // output different welcome information based on the value of userflag if ($ flag = 1) echo "Welcome administrator ". $ _ SESSION ['username']. "log on to the system"; if ($ flag = 0) echo "welcome ". $ _ SESSION ['username']. "log on to the system"; echo "log off";} else {echo "You are not authorized to access this page" ;}?>
<? Phpsetcookie ("username"); echo "logout successful";?>