Advertisement
Guest User

Untitled

a guest
May 16th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. -- js file
  2. function makeXHR(){
  3. var xhr = null;
  4. try {
  5. xhr = new XMLHttpRequest(); // Firefox, Opera, ...
  6. } catch(err1) {
  7. try {
  8. xhr = new ActiveXObject("Microsoft.XMLHTTP"); //Noen IE
  9. } catch(err2) {
  10. try {
  11. xhr = new ActiveXObject("Msxml2.XMLHTTP"); //Noen IE
  12. } catch(err3) {
  13. xhr = null;
  14. }
  15. }
  16. }
  17. return xhr;
  18. }
  19.  
  20. var xmlhttp;
  21.  
  22. function getMsgFromServer(){
  23. xmlhttp = makeXHR();
  24. if(xmlhttp == null){
  25. alert("Your browser does not support xmlhttp");
  26. return;
  27. }
  28. var url = "passwordcheck.php";
  29. url += "?user="+document.getElementById("user").value;
  30. url += "&pass="+document.getElementById("pass").value;
  31. url=url+"&sid="+Math.random();
  32. xmlhttp.onreadystatechange=stateChanged;
  33. xmlhttp.open("GET",url,true);
  34. xmlhttp.send(null);
  35. }
  36.  
  37. function stateChanged()
  38. {
  39. if (xmlhttp.readyState==4)
  40. {
  41. document.getElementById("messageGoesHere").innerHTML=xmlhttp.responseText;
  42. }
  43. }
  44.  
  45. -- html file
  46.  
  47. <!--
  48. To change this template, choose Tools | Templates
  49. and open the template in the editor.
  50. -->
  51. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  52. <html>
  53. <head>
  54. <title>Oppgave 1</title>
  55. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  56. <script src="jsfuncs.js" type="text/javascript"></script>
  57. </head>
  58. <body>
  59. <form>
  60. Username: <input type="text" id="user"/>
  61. <br>
  62. Password: <input type="text" id="pass"/>
  63. <br>
  64. <input type="submit" onclick="getMsgFromServer()"/>
  65. </form>
  66. <div id="messageGoesHere">
  67.  
  68. </div>
  69. </body>
  70. </html>
  71.  
  72.  
  73. ---- php file ---
  74.  
  75. <?php
  76. //checks if username and password are as expected.
  77.  
  78. if ( ($_GET['user'] == "john")
  79. &&
  80. ($_GET['pass'] == "1234")
  81. ) {
  82. echo "Dis be secret message";
  83. }
  84. else {
  85. echo "You are gay";
  86. }
  87. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement