php - HTML Forms two actions -


so have form action link verifies user's username , password (can't post link not belong me) , if it's correct gives me "ok" or else "no" how can make in way if yes directs me index page , if no gives error or reloads page or something. way general html appearance is:

 <form method="post" action="https://***************/login">         <label for="book">username:</label>         <input type="text" name="username" id="username" placeholder="enter username">         <label for="course">password:</label>         <input type="password" name="password" id="password" placeholder="enter password">         <input type="submit" value="log in">     </form> 

so if change way want action should change verify.php have appearance of

<?php     # how use if link using info input     if($_post["https://***************/login"]){          #load index.html  ?>         <script type="text/javascript">              window.location.href = 'index.html';         </script> <?php     else{          #load page again ?>         <script type="text/javascript">              window.location.href = 'login.php';         </script> <?php              } ?> 

i'm bit new php. please help

being unable edit login verification file, think best option submit form via ajax , handle response javascript, having form like

<form method="post" action="" onsubmit="return false;">     <label for="book">username:</label>     <input type="text" name="username" id="username" placeholder="enter username">     <label for="course">password:</label>     <input type="password" name="password" id="password" placeholder="enter password">     <input type="submit" value="log in" onclick="btnauthenticateuser();"> </form> 

then, in plain javascript like

<script type="text/javascript"> var xmlhttp; function getxmlhttpobject() {     var xmlhttp = null;     try {         xmlhttp = new xmlhttprequest();     }     catch (e) {         try {             xmlhttp = new activexobject("msxml2.xmlhttp");         }         catch (e) {             xmlhttp = new activexobject("microsoft.xmlhttp");         }     }     return xmlhttp; } function btnauthenticateuser() {     try {         var username = document.getelementbyid('username');         var pwd = document.getelementbyid('password');         xmlhttp = getxmlhttpobject();         if (xmlhttp == null) {             alert("your browser not support ajax!");             return;         }         var url = 'https://***************/login?username=' + username.value + '&password=' + pwd.value;         xmlhttp.onreadystatechange = function () {             if (xmlhttp.readystate == 4) {                 if (xmlhttp.status == 200) {                     if (xmlhttp.responsetext == "ok") {                         window.location = "index.html";                      } else {                         location.reload();                     }                 }                 if (xmlhttp.readystate == 4) {                     // loadingpage                 }             }         }         xmlhttp.open("post", url, true);         xmlhttp.send(null);         if (xmlhttp.readystate == 1) {             //loadingpage         }     } catch (e) {         alert(e.message);     } } </script> 

or if you're using jquery

function btnauthenticateuser() {     $.ajax({         async: true,         type: 'post',          url: 'https://***************/login',          data: { username: $('#username').val(), password: $('#password').val()}      })     .done(function (data) {         if (data == "ok") {             window.location = "index.html";         }else{             location.reload();         }     })     .fail(function (jqxhr, textstatus, error) {          gritererror(global.failtryagain);     }); } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -