Guest User

Untitled

a guest
Nov 25th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. <?php
  2.  
  3. //Setting values for the database
  4. $servername = "";
  5. $username = "";
  6. $password = "";
  7. $dbname = "";
  8.  
  9. //Connecting the database
  10. $conn = mysqli_connect($servername, $username, $password,$dbname);
  11. $email = $_POST['email'];
  12. $msg = $_POST['msg'];
  13. $noti =$_POST['noti'];
  14. echo "Submitted";
  15.  
  16. //Retrievin Registration ID from the database with the help of email
  17. $sql = "SELECT regid FROM gcm where email='"'.$email.'"'";
  18.  
  19. //Executing the query
  20. $result = mysqli_query($conn, $sql);
  21. if (mysqli_num_rows($result) > 0) {
  22. $regid = mysqli_fetch_assoc($result);
  23. } else {
  24. echo "0 results";
  25. }
  26.  
  27. //closing the database connection
  28. mysqli_close($conn);
  29.  
  30. //Setting Server API Key that we generated in the Google Developer Console
  31. define( 'API_ACCESS_KEY', 'ENTER YOUR OWN API KEY' );
  32.  
  33. //Storing Fetched Registration ID to the vaiable 'to'. 'to' is an array of registration IDs whom we want to send push notification
  34. $to=$regid;
  35.  
  36. //This 'to' is assigned to registrationIds
  37. $registrationIds = array($to);
  38.  
  39. //Message Array
  40. $msg = array
  41. (
  42.  
  43. //Message that we want to send in the push notification
  44. 'message' => $msg,
  45.  
  46. //Title that we want to set for the push notification
  47. 'title' => $noti,
  48.  
  49. //Subtitle, ticker text
  50. 'subtitle' => 'This is a subtitle. subtitle',
  51. 'tickerText' => 'Ticker text here...Ticker text here...Ticker text here',
  52.  
  53. //Sets to true or '1' if we want device to vibrate and make sound when user recieves push notification
  54. 'vibrate' => 1,
  55. 'sound' => 1,
  56. 'largeIcon' => 'large_icon',
  57. 'smallIcon' => 'small_icon'
  58. );
  59.  
  60. //RegistrationIds and message are assigned to fields
  61. $fields = array
  62. (
  63. 'registration_ids' => $registrationIds,
  64. 'data' => $msg
  65. );
  66. $headers = array
  67. (
  68.  
  69. //Setting headers for API acceess key and content type
  70. 'Authorization: key=' . API_ACCESS_KEY,
  71. 'Content-Type: application/json'
  72. );
  73.  
  74. //Initializing Curl
  75. $ch = curl_init();
  76.  
  77. //Posting data to the following URL
  78. curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
  79.  
  80. //Post Data = True, Defining Headers and SSL Verifier = false
  81. curl_setopt( $ch,CURLOPT_POST, true );
  82. curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
  83. curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
  84. curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
  85.  
  86. //Posting fields array in json format
  87. curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
  88.  
  89. //Executing Curl
  90. $result = curl_exec($ch );
  91.  
  92. //Closing Curl
  93. curl_close( $ch );
  94. echo $result;
  95. ?>
  96. <!DOCTYPE html>
  97. <html>
  98. <head>
  99. <meta name="format-detection" content="telephone=no">
  100. <meta name="msapplication-tap-highlight" content="no">
  101. <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
  102. <title>Send Me </title>
  103.  
  104. <!--Stylesheet Files : jQuery Mobile CSS File, Customized CSS File-->
  105. <link rel="stylesheet" href="css/jquery.mobile-1.4.5.css">
  106. <link rel="stylesheet" href="css/my.css">
  107.  
  108. <!--AJAX Library, jQuery File : Library,and Mobile Library -->
  109. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  110. <script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
  111. <script type="text/javascript" src="js/jquery.mobile-1.4.5.js"></script>
  112. </head>
  113.  
  114. <!--Beginning of the Body-->
  115. <body>
  116. <div data-role="page">
  117. <div data-role="header" data-position="fixed" class="ui-header ui-bar-a ui-header-fixed slidedown" role="banner">
  118. <h1>Send Me</h1>
  119. </div>
  120. <div data-role="main" class="ui-content" id="main">
  121.  
  122. <!--Form containing fields registered email, message user wants to send, title of the push notification and submit button-->
  123. <form action="http://juth.esy.es/sendnotification.php" method="post">
  124. <ul data-role="listview" data-inset="true">
  125. <li class="ui-field-contain">
  126. <label for="name2">Enter Your Registered Email:</label>
  127. <input type="text" name="email" id="email" value="" data-clear-btn="true">
  128. </li>
  129. <li class="ui-field-contain">
  130. <label for="name2">Enter Your Message:</label>
  131. <input type="text" name="msg" id="message" value="" data-clear-btn="true">
  132. </li>
  133. <li class="ui-field-contain">
  134. <label for="name2">Enter Notification Title:</label>
  135. <input type="text" name="noti" id="notification" value="" data-clear-btn="true">
  136. </li>
  137. <li class="ui-body ui-body-b">
  138. <center><input type="submit" id="submit" value="Send Notification" class="ui-shadow ui-btn ui-corner-all"/></center>
  139. </li>
  140. </ul>
  141. </form>
  142. <!--End of the form-->
  143.  
  144. /div>
  145. </div>
  146. </body>
  147. <!--End of the body-->
  148. </html>
Add Comment
Please, Sign In to add comment