PHP login page information prompt function example, php example
This example describes the logon page information prompt function implemented by PHP. We will share this with you for your reference. The details are as follows:
Login. php:
<! DOCTYPE html>
Check_login.php:
<? Phpheader ("Content-type: text/html; charset = UTF-8"); session_start (); // initialize the session variable $ username = $ _ POST ['name']; // user name for receiving form submission $ password = md5 ($ _ POST ['pwd']); // password class chkinput for receiving form submission // definition class {var $ name; var $ pwd; function chkinput ($ x, $ y) // define a method {$ this-> name = $ x; // pass the Administrator name to the Class Object $ this-> name $ this-> pwd = $ y; // send the administrator password to the Class Object $ this-> pwd} function checkinput () {include ("conn. php "); // connect to the database file $ SQL = mysql_query (" sel Ect username, password from admin where username = '". $ this-> name. "'and password = '". $ this-> pwd. "'", $ conn); $ info = mysql_fetch_array ($ SQL); // retrieve the Administrator name and password if ($ info = false) // If the Administrator name or password is incorrect, the prompt {header ("location: login. php? Error = 1 "); exit;} else // If the Administrator name or password is correct, go directly to the interface {header (" location: login. php? Error = 2 "); $ _ SESSION ['admin _ name'] = $ info ['username']; // Save the Administrator name to the $ _ SESSION [admin_name] variable $ _ SESSION ['pwd'] = $ info ['Password']; /// Save the Administrator name to the $ _ SESSION [pwd] variable }}$ obj = new chkinput (trim ($ username), trim ($ password )); // create an object $ obj-> checkinput (); // call class?>
Conn. php:
<? Phpheader ("Content-type: text/html; charset = UTF-8"); $ conn = mysql_connect ("localhost", "root", "111111"); if (! $ Conn) {die ("failed to connect to the Database ". mysql_error ();} mysql_select_db ("design") or die ("database selection failed ". mysql_error (); mysql_query ("set names 'uft8'");?>