Advertisement
vir0e5

Notifikasi

Feb 22nd, 2014
102
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [NOTIFIKASI JIKA DATA MASUK KE TABLE]
  2. MYSQL (Buat Dulu DB ['counter'])
  3. -----------------
  4. DROP TABLE IF EXISTS `konter1`;
  5. CREATE TABLE `konter1` (
  6.   `member_id` varchar(20) DEFAULT NULL,
  7.   `ip` varchar(20) DEFAULT NULL,
  8.   `total_unik` varchar(20) DEFAULT NULL,
  9.   `tanggal` date NOT NULL
  10. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  11.  
  12. /*---------------------------------*/
  13. periksa-tabel.php
  14. /*--------------------------------*/
  15. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
  16. <?php
  17. function get_random_string($valid_chars, $length)
  18. {
  19.     $random_string = "";
  20.     $num_valid_chars = strlen($valid_chars);
  21.     for ($i = 0; $i < $length; $i++)
  22.     {
  23.         $random_pick = mt_rand(1, $num_valid_chars);
  24.         $random_char = $valid_chars[$random_pick-1];
  25.         $random_string .= $random_char;
  26.     }
  27.     return $random_string;
  28. }
  29. $original_string = 'abcdefghijklmnopqrstuvwxyz';
  30. $random_string = get_random_string($original_string, 6);
  31.  
  32. $host = "localhost";
  33. $user = "root";
  34. $pass = "";
  35. $db = "counter";
  36.  
  37. $ip  = $_SERVER['REMOTE_ADDR'];
  38. $tanggal = date("Y-m-d");
  39.  
  40. $konek = mysql_connect ($host, $user, $pass);
  41. if ($konek) {
  42.     $isi = mysql_select_db ($db);
  43.     if (!$isi) {
  44.         die ("Teu aya Database-an");   
  45.     }
  46. } else {
  47.     die ("Teu Konak Mysql");   
  48. }
  49.  
  50. $cek_id=mysql_num_rows(mysql_query ("SELECT member_id FROM konter1 WHERE member_id='$random_string' "));
  51. if ($cek_id > 0){
  52.     echo "AYA NU SARUA!!!!";
  53. }
  54. else{
  55.   $asup = "INSERT INTO konter1(member_id,  ip, total_unik,tanggal) VALUES ('$random_string','$ip', 1,'$tanggal')";
  56.   $asupTOKEN=mysql_query($asup);
  57.   ?>
  58.  <script type="text/javascript">
  59. $("#sound").remove();
  60. var sound = $("<embed id='sound' type='audio/mpeg' />");
  61. sound.attr('src', 'notify.mp3');
  62. sound.attr('loop', false);
  63. sound.attr('hidden', true);
  64. sound.attr('autostart', true);
  65. $('body').append(sound);
  66. </script>
  67. <?php
  68. }  
  69. ?>
  70.  
  71. /*---------------------*/
  72. load.php
  73. /*------------------------*/
  74. <!doctype html>
  75. <html lang="en">
  76. <head>
  77. <meta charset="utf-8">
  78. <style>
  79. body{font-size:12px;background-color:#eee;font-family:Arial, Helvetica, sans-serif}
  80. table.gridtable{color:#333;border-collapse:collapse;border-color:#666;border-width:1px}
  81. table.gridtable th{background-color:#dedede;border-color:#666;border-style:solid;border-width:1px;padding:8px}
  82. table.gridtable td{background-color:#fff;border-color:#666;border-style:solid;border-width:1px;padding:8px}
  83. </style>
  84. <!--<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>-->
  85. <script type="text/javascript" src="jquery.min.js"></script>
  86. </head>
  87. <script type="text/javascript">
  88.         var auto_refresh = setInterval(
  89.         function ()
  90.         {
  91.         $('#load_content').load('periksa-table.php').fadeIn("slow");
  92.         }, 10000);
  93. </script>
  94. <body>
  95.  
  96. <div id="load_content"> </div>
  97. <?php
  98. $host = "localhost";
  99. $user = "root";
  100. $pass = "";
  101. $db = "counter";
  102. $ip  = $_SERVER['REMOTE_ADDR'];
  103. $tanggal = date("Y-m-d");
  104.  
  105. $konek = mysql_connect ($host, $user, $pass);
  106. if ($konek) {
  107.     $isi = mysql_select_db ($db);
  108.     if (!$isi) {
  109.         die ("Teu aya Database-an");   
  110.     }
  111. } else {
  112.     die ("Teu Konak Mysql");   
  113. }
  114. $result22 = mysql_query("SELECT member_id FROM konter1");
  115. $num_rows2 = mysql_num_rows($result22);
  116.  
  117. $result = mysql_query("SELECT * FROM konter1")
  118. or die(mysql_error());  
  119.  
  120. echo "<table style='background: #fff;' border='0' cellpadding='0' cellspacing='1px' class='gridtable'>";
  121. echo "<tr> <th>MEMBER ID</th> <th>IP ADDRESS</th> </tr>";
  122. while($row = mysql_fetch_array( $result )) {
  123.     echo "<tr><td>";
  124.     echo $row['member_id'];
  125.     echo "</td><td>";
  126.     echo $row['ip'];
  127.     echo "</td></tr>";
  128. }
  129. echo "</table>";
  130. ?>
  131.  
  132. </body>
  133. </html>
Advertisement
RAW Paste Data Copied
Advertisement