PHP script login. php: A simple example of AJAX combined with PHP code to achieve the login effect code
HTML section:
XML/HTML code
-
- Function postRequest (strURL ){
- Var xmlHttp;
- If (window. XMLHttpRequest) {// For Mozilla, Safari ,...
- Var xmlHttp = new XMLHttpRequest ();
- }
- Else if (window. ActiveXObject) {// For Internet Explorer
- Var xmlHttp = new ActiveXObject ("Microsoft. XMLHTTP ");
- }
- XmlHttp. open ('post', strURL, true );
- XmlHttp. setRequestHeader ('content-type', 'application/x-www-form-urlencoded ');
- XmlHttp. onreadystatechange = function (){
- If (xmlHttp. readyState = 4 ){
- Updatepage (xmlHttp. responseText );
- }
- }
- XmlHttp. send (strURL );
- }
- Function updatepage (str ){
- If (str = "yes "){
- Alert ("Welcome User ");
- } Else {
- Alert ("Invalid Login! Please try again! ");
- }
- }
- Function call_login (){
- Var username = parameter doc ument. f1.username. value;
- Var password = parameter doc ument. f1.password. value;
- Var url = "login. php? Username = "+ username +" password = "+ password;
- PostRequest (url );
- }
-
PHP script login. php:
PHP code
-
- $ Username = $ _ GET ["username"];
- $ Password = $ _ GET ["password"];
- If ($ username = "admin" & $ password = "admin "){
- Echo "yes ";
- } Else {
- Echo "No ";
- }
- ?>