Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- js file
- function makeXHR(){
- var xhr = null;
- try {
- xhr = new XMLHttpRequest(); // Firefox, Opera, ...
- } catch(err1) {
- try {
- xhr = new ActiveXObject("Microsoft.XMLHTTP"); //Noen IE
- } catch(err2) {
- try {
- xhr = new ActiveXObject("Msxml2.XMLHTTP"); //Noen IE
- } catch(err3) {
- xhr = null;
- }
- }
- }
- return xhr;
- }
- var xmlhttp;
- function getMsgFromServer(){
- xmlhttp = makeXHR();
- if(xmlhttp == null){
- alert("Your browser does not support xmlhttp");
- return;
- }
- var url = "passwordcheck.php";
- url += "?user="+document.getElementById("user").value;
- url += "&pass="+document.getElementById("pass").value;
- url=url+"&sid="+Math.random();
- xmlhttp.onreadystatechange=stateChanged;
- xmlhttp.open("GET",url,true);
- xmlhttp.send(null);
- }
- function stateChanged()
- {
- if (xmlhttp.readyState==4)
- {
- document.getElementById("messageGoesHere").innerHTML=xmlhttp.responseText;
- }
- }
- -- html file
- <!--
- To change this template, choose Tools | Templates
- and open the template in the editor.
- -->
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <title>Oppgave 1</title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <script src="jsfuncs.js" type="text/javascript"></script>
- </head>
- <body>
- <form>
- Username: <input type="text" id="user"/>
- <br>
- Password: <input type="text" id="pass"/>
- <br>
- <input type="submit" onclick="getMsgFromServer()"/>
- </form>
- <div id="messageGoesHere">
- </div>
- </body>
- </html>
- ---- php file ---
- <?php
- //checks if username and password are as expected.
- if ( ($_GET['user'] == "john")
- &&
- ($_GET['pass'] == "1234")
- ) {
- echo "Dis be secret message";
- }
- else {
- echo "You are gay";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement