Guest User

Untitled

a guest
May 27th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. var app = {
  2.  
  3. initialize: function() {
  4. this.bindEvents();
  5. },
  6.  
  7. bindEvents: function() {
  8. document.addEventListener('deviceready', this.onDeviceReady, false);
  9. },
  10.  
  11. onDeviceReady: function() {
  12. var push = PushNotification.init({
  13. "android": {
  14. "senderID": "xxxxxxxxx"
  15. },
  16. "ios": {"alert": "true", "badge": "true", "sound": "true"},
  17. "windows": {}
  18. });
  19.  
  20. push.on('registration', function(data) {
  21. console.log("registration event");
  22. var gcm_regid = data.registrationId;
  23. $.post('http://xxxxx.xxx/insert.php', {gcm_regid: gcm_regid});
  24. return false;
  25. });
  26.  
  27. <?php
  28. $con = mysql_connect("localhost","gcm","password");
  29. if (!$con) {
  30. die('Could not connect: ' . mysql_error());
  31. }
  32. mysql_select_db("gcm", $con);
  33. $gcm_regid=$_POST['gcm_regid'];
  34.  
  35. $query=mysql_query("INSERT INTO gcm_users(gcm_regid) VALUES('$gcm_regid')");
  36. if($query){
  37. echo "Data for $gcm_regid inserted successfully!";
  38. }
  39. else{ echo "An error occurred!"; }
  40. ?>
  41.  
  42. id -> int(11) --> AUTO_INCREMENT
  43. gcm_regid text
  44. created_at --> timestamp -> CURRENT_TIMESTAMP
  45.  
  46. ALTER IGNORE TABLE gcm_users
  47. ADD UNIQUE INDEX idx_name (gcm_regid);
Add Comment
Please, Sign In to add comment