As we all know that using GET method for login (or sending sensitive information) is not suggested. I want to create login functionality using XMLHTTPRequest. Following are my steps:
- User enters username and password and clicks on Submit button
- Submit button invokes an XMLHTTPRequest
- XMLHTTPRequest sends the credential to a PHP page which will verify
it - If credentials are right then create session otherwise show error message
without refreshing the login screen.
My question is:
How can I transfer login credentials to a PHP page using POST (securely)? If I am using the open method as shown below with GET then I think it is not secure. Can I replace GET with POST? If yes, then how to transfer credentials?
xmlhttp.open("GET","verifyCredentials.php",true);
To post data using POST method, set the method in
opentoPOST, set the Content-Type request header field toapplication/x-www-form-urlencoded, encode your data accordingly, and pass it as parameter value tosend:You can use the
encodeURIComponentfunction to encode your data:Note that with this the data is still transferred unprotected against eavesdropping.