Advertisement
Guest User

code of my chat app for Michiman

a guest
Mar 4th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. chat.html:
  2. <!DOCTYPE HTML>
  3. <html>
  4. <head>
  5. <script>
  6. setInterval(
  7. function getChatMessages () {
  8. if(window.XMLHttpRequest){
  9. xmlhttp = new XMLHttpRequest();
  10. }
  11. else{
  12. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  13. }
  14. xmlhttp.onreadystatechange = function () {
  15. if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
  16. document.getElementById("chat").innerHTML = xmlhttp.responseText;
  17. }
  18. }
  19. xmlhttp.open("GET", "gchat.php", true);
  20. xmlhttp.send();
  21. }, 1);
  22. </script>
  23. <link href="chatStyle.css" rel="stylesheet">
  24. </head>
  25. <body style="background-color:gray">
  26. <div class="main-chat-wrapper">
  27. <div class="listusers">
  28. All users:<br/>
  29. <a href="users/foo">foo</a>, <a href="/users/bar">bar</a>
  30. </div>
  31. <div class="chat-wrapper">
  32. <div class="chat-output-feed" id="chat">
  33.  
  34. </div>
  35. <form action="chat.php">
  36. Send a message to your friends:
  37. <input class="msg" type="text" name="msg" />
  38. <input type="submit" value="Send!" />
  39. </form>
  40. </div>
  41. </div>
  42. </body>
  43. </html>
  44. chat.php:
  45. <?php
  46.  
  47. $server = "tcp:s0rq688sz1.database.windows.net,1433";
  48. $user = "raumaan@s0rq688sz1";
  49. $pwd = "Qwertyuiop1";
  50. $db = "raumaansql";
  51.  
  52. $connectionInfo = array("UID" => "raumaan@s0rq688sz1", "pwd" => "Qwertyuiop1", "Database" => "raumaansql", "LoginTimeout" => 30, "Encrypt" => 1);
  53. $serverName = "tcp:s0rq688sz1.database.windows.net,1433";
  54.  
  55. $conn = sqlsrv_connect($serverName, $connectionInfo);
  56.  
  57. if($conn === false){
  58. die(print_r(sqlsrv_errors()));
  59. }
  60. $sql = "INSERT INTO chat VALUES ('foo',?)";
  61. $params = array($_GET['msg']);
  62. $stmt = sqlsrv_query($conn, $sql, $params);
  63. if($stmt === false){
  64. die(print_r(sqlsrv_errors(), true));
  65. }
  66. sqlsrv_close($conn);
  67. ?>
  68. <!DOCTYPE HTML><html><head><meta http-equiv="refresh" content="0;url=chat.html"/></head></html>
  69. gchat.php:
  70. <?php
  71. $server = "tcp:s0rq688sz1.database.windows.net,1433";
  72. $user = "raumaan@s0rq688sz1";
  73. $pwd = "Qwertyuiop1";
  74. $db = "raumaansql";
  75.  
  76. $connectionInfo = array("UID" => "raumaan@s0rq688sz1", "pwd" => "Qwertyuiop1", "Database" => "raumaansql", "LoginTimeout" => 30, "Encrypt" => 1);
  77. $serverName = "tcp:s0rq688sz1.database.windows.net,1433";
  78.  
  79. $conn = sqlsrv_connect($serverName, $connectionInfo);
  80.  
  81. if($conn === false){
  82. die(print_r(sqlsrv_errors()));
  83. }
  84. $sql = "SELECT * FROM chat";
  85. $stmt = sqlsrv_query($conn, $sql);
  86. if($stmt === false){
  87. die(print_r(sqlsrv_errors(), true));
  88. }
  89. while($row = sqlsrv_fetch_array($stmt)) {
  90. echo $row['username'] . "&#155; " . $row['message'] . "<br/>";
  91. }
  92. sqlsrv_close($conn);
  93. ?>
  94. link: raumaan.azurewebsites.net/chat.html
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement