Advertisement
Guest User

Untitled

a guest
May 24th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. GET_AJAX.PHP
  2.  
  3. <?php
  4.  
  5. //$date=$_GET["date"];
  6.  
  7. include ("db_config.php");
  8. include ("config.php");
  9.  
  10. $sql="";
  11. $date="";
  12.  
  13.  
  14. $sqls[1]="SELECT l.ip,l.browser,l.datetime,u.username FROM `log` as l,user as u WHERE u.user_id=l.user_id ORDER BY l.datetime DESC";
  15. $sqls[2]="SELECT l.ip,l.browser,l.datetime,u.username FROM `log` as l,user as u WHERE u.user_id=l.user_id AND DATE(l.datetime)='$date' ORDER BY l.datetime DESC";
  16. if(isset($_POST['sql']) AND isset($_POST['date']))
  17. {
  18. $sql=(int)mysqli_real_escape_string($connection,$_POST['sql']);
  19. if(($sql>=1 OR $sql<=2))
  20. {
  21. $result= mysqli_query($connection,$sqls[$sql]) or die(mysqli_error($connection));
  22.  
  23. if (mysqli_num_rows($result)>0)
  24. {
  25. while ($record = mysqli_fetch_array($result,MYSQLI_BOTH))
  26. {
  27. echo "User: $record[username]<br /> Browser: $record[browser]<br /> IP address:$record[ip]<br /> Date and time:$record[datetime] <br /><br />";
  28. }
  29. }
  30. }
  31. else
  32. echo "No access!!";
  33. }
  34. else
  35. echo "No access!";
  36. ?>
  37.  
  38.  
  39. ----------------------------------------------------------------------------------------
  40. INDEX.PHP
  41.  
  42. <html>
  43. <head>
  44.  
  45. </head>
  46. <body>
  47. <div>
  48. <form>
  49. <input id="buttonV" type="button" value="View Log">
  50. </form>
  51. </div>
  52.  
  53. <div>
  54. <form>
  55. Day:
  56. <select name="day" id="day">
  57. <?PHP for($i=1; $i<=31; $i++)
  58. echo "<option value='$i'>$i</option>";
  59. ?>
  60. </select>
  61. Month:
  62. <select name="month" id="month">
  63. <?PHP for($i=1; $i<=12; $i++)
  64. echo "<option value='$i'>$i</option>";
  65. ?>
  66. </select>
  67. Year:
  68. <select name="year" id="year">
  69. <?PHP for($i=1980; $i<=2016; $i++)
  70. echo "<option value='$i'>$i</option>";
  71. ?>
  72. </select>
  73. <input type="button" value="see users by date" id="buttonD">
  74. </form>
  75. <br />
  76. </div>
  77. <div id="button_values"></div><br />
  78. <hr>
  79. <div id="select_values"></div>
  80.  
  81. <script type="text/javascript">
  82.  
  83. var year = document.getElementById("year");
  84. var month = document.getElementById("month");
  85. var day = document.getElementById("day");
  86. var date=year+'-'+month+'-'+day;
  87.  
  88. document.getElementById("buttonV").addEventListener('click',function(){showUser(1,'button_values')});
  89. document.getElementById("buttonD").addEventListener('click',function(){showUser(2,'select_values')});
  90.  
  91.  
  92. function showUser(sql,div)
  93. {
  94. var xmlhttp;
  95. if (window.XMLHttpRequest)
  96. {// code for IE7+, Firefox, Chrome, Opera, Safari
  97. xmlhttp=new XMLHttpRequest();
  98. }
  99. else
  100. {// code for IE6, IE5
  101. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  102. }
  103. xmlhttp.onreadystatechange=function()
  104. {
  105. document.getElementById(div).innerHTML='<img src="ajax_loader.gif" />';
  106. if (xmlhttp.readyState==4 && xmlhttp.status==200)
  107. {
  108. document.getElementById("button_values").innerHTML=xmlhttp.responseText;
  109. }
  110. };
  111. xmlhttp.open("POST","get_ajax.php",true);
  112. xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  113. xmlhttp.send("sql="+sql+"date="+date);
  114.  
  115. }
  116. </script>
  117.  
  118. </body>
  119. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement