Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. <?php
  2.  
  3. if (isset($_POST['newCookie']))
  4. {
  5. $cookie_name = "authKey";
  6. $cookie_value = md5(microtime());
  7. setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
  8. echo "<h2 align='center'> authKey Cookie SET! </h2>";
  9. }
  10.  
  11. if (isset($_POST['outputCookie']))
  12. {
  13. if(isset($_COOKIE['authKey']))
  14. {
  15. echo "<h2 align='center'> authKey Cookie: ".$_COOKIE['authKey']."</h2>";
  16. }
  17. else
  18. {
  19. echo "<h2 align='center'> authKey Cookie: NOT SET </h2>";
  20. }
  21. }
  22.  
  23. $servername = "localhost";
  24. $username = "root";
  25. $password = "";
  26. $dbname = "xss3";
  27.  
  28. // Create connection
  29. $conn = new mysqli($servername, $username, $password, $dbname);
  30. // Check connection
  31. if ($conn->connect_error) {
  32. die("Connection failed: " . $conn->connect_error);
  33. }
  34.  
  35. if (isset($_POST['clear']))
  36. {
  37. $sql = "TRUNCATE TABLE comments";
  38. if ($conn->query($sql) === TRUE)
  39. {
  40. echo "Table Cleared";
  41. } else {
  42. echo "Error: Unable to Clear Table". $conn->error;
  43. }
  44. }
  45.  
  46. if (isset($_POST['comment']))
  47. {
  48. $sql = "INSERT INTO comments (comment)
  49. VALUES ('".addslashes($_POST['comment'])."')";
  50. }
  51.  
  52. ?>
  53. <!DOCTYPE html>
  54. <html>
  55. <title> XSS Tutorial #4 </title>
  56. <style>
  57. #bord td
  58. {
  59. border: 1px solid black;
  60. border-collapse: collapse;
  61. }
  62. </style>
  63. <body>
  64. <h1 align="center"> Try My New Comment & Cookie Website! </h1>
  65. <table align="center">
  66. <tr><td>
  67. <p>
  68. <?php
  69. if (isset($_GET['name']))
  70. {
  71. echo "<p align='center'>Hey there ".$_GET['name']."! Welcome!</p>";
  72. }
  73. if (isset($_POST['comment']))
  74. {
  75. if ($conn->query($sql) === TRUE)
  76. {
  77. echo "New record created successfully";
  78. } else {
  79. echo "Error: Unable to add comment";
  80. }
  81. }
  82. ?>
  83. </p>
  84. <form action="index.php" method="post" id="post">
  85. <textarea rows="6" cols="50" name="comment" placeholder="Leave a comment" maxlength="400"></textarea>
  86. <table align="center"><tr><td>
  87. <input type="submit" value="Comment" />
  88. </td></tr></table>
  89. </form>
  90. <form action="index.php" method="post">
  91. <table align="center"><tr><td>
  92. <input type="submit" name="newCookie" value="New Cookie" />
  93. <input type="submit" name="outputCookie" value="Output Cookie" />
  94. </td></tr></table>
  95. </form>
  96. <form action="index.php" method="get">
  97. <table align="center"><tr><td>
  98. Name:<input type="text" name="name" />
  99. <input type="submit" value="Submit" />
  100. </td></tr></table>
  101. </form>
  102. </td></tr>
  103. </table>
  104. <br />
  105. <br />
  106. <table align="center" id="bord">
  107. <?php
  108. $sql = "SELECT id, comment FROM comments";
  109. $result = $conn->query($sql);
  110.  
  111. if ($result->num_rows > 0) {
  112. // output data of each row
  113. while($row = $result->fetch_assoc()) {
  114. echo "<tr><td style='width:35%;padding:10px'>Comment #".$row["id"]."<br /><hr />".$row["comment"]."<br /></td></tr>";
  115. }
  116. } else {
  117. echo "<tr><td style='width:35%'>No Comments!</td></tr>";
  118. }
  119. $conn->close();
  120. ?>
  121. </table>
  122. <h3 align="center"> This website was made by me! I hope you really really like it! </h3>
  123. <table align="center">
  124. <tr><td>
  125. <form action="index.php" method="post">
  126. Debug: <input type="submit" name="clear" value="Clear Table" />
  127. </form>
  128. </td></tr>
  129. </table>
  130. </body>
  131. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement