Using the PHP jump interface and Ajax can be used to implement the login interface to jump the login failure of the reminder. However, the way PHP jumps
Additional interfaces need to be loaded and the user experience is poor. Ajax enables the current page to refresh only the required data, not the current page
Reload or jump.
To do a simple login interface:
<div id= "" > User name: <input type= "text" name= "" id= "UID" value= ""/></div><div id= "" > Password: <input ty Pe= "text" name= "" id= "pwd" value= ""/></div><div id= "" ><input type= "button" name= "" id= "Denglu" value = "Login"/></div>
Then the JS code, the use of JQ is relatively simple, so first introduce the JQ file package.
Next get the user name and password value:
var uid = $ ("#uid"). Val (); var pwd = $ ("#pwd"). Val ();
After setting up, you can set up Ajax:
$.ajax ({type: "post", url: "dengluchuli.php", data: {u:uid,p:pwd},datatype: "TEXT", Success:function (r) { /// R is the return value if (r.trim () = = "Y") { //y is the value returned in the URL Jump Web page. Window.location.href = "Jump Interface";} else {alert ("User name or password error");}});
dengluchuli.php:
<?phpinclude ("AJAXLOGIN.class.php"), $dd = new LoGin ($_post["U"],$_post["P"]); $ae = $dd:: Logi ("Login", "username", "password", "name"); is the table name in the database , the user name in the table, the password, the name (the data is imported from the database)?>
Here I introduced a login class (AJAXLOGIN.class.php), which is intended for later convenience:
<?phpclass dbda{public $host = "localhost";p ublic $uid = "root";p ublic $pwd = "";p ublic $dbname = "12345";//Member Method public fu Nction Query ($sql, $type =1) {$db = new mysqli ($this->host, $this->uid, $this->pwd, $this->dbname); $r = $db- >query ($sql), if ($type ==1) {return $r->fetch_all ();} Else{return $r;}}} Class login{public static $uid;p ublic static $pwd; function __construct ($x, $y) {self :: $uid = $x; Self:: $pwd = $y; } static function Logi ($table, $username, $password, $name) {$db = new Dbda (); $nnn = self:: $uid; $sql = "Select $name, $password From $table where $username = ' $nnn ', $at = $db->query ($sql), $p = self:: $pwd, if (!empty ($p) && $p = = $at [0][1]) {$ _session["UID"]= $at [0][0];echo "Y";} Else{echo "n";}}? >
Login Interface Complete code:
<!doctype html>
Ajax Implementation Login Interface