title: sending push notifications to multiple android devices using GCM
body: <p>I am following <a href="http://javapapers.com/android/google-cloud-messaging-gcm-for-android-and-push-notifications/" rel="noreferrer">http://javapapers.com/android/google-cloud-messaging-gcm-for-android-and-push-notifications/</a>? to send push notifications via GCM. Everything works fine but, i am able to send push notification to just one device. Registering another device replaces registration id of previous device. I tried solution provided by Shardool in <a href="http://javapapers.com/android/android-multicast-notification-using-google-cloud-messaging-gcm/" rel="noreferrer">http://javapapers.com/android/android-multicast-notification-using-google-cloud-messaging-gcm/</a>? but its not working. </p>
  
  <p>Any suggestion would be of great help. </p>
  
  <p>Here are my <code>gcm.php</code> codes that registers device and sends push notifications but, only to a single device registered recently.</p>
  
  <p><strong>gcm.php</strong></p>
  
  <pre><code>&lt;?php
  //generic php function to send GCM push notification
  function sendPushNotificationToGCM($registatoin_ids, $message) {
      //Google cloud messaging GCM-API url
      $url = 'https://android.googleapis.com/gcm/send';
      $fields = array(
          'registration_ids' =&gt; $registatoin_ids,
          'data' =&gt; $message,
      );
      // Google Cloud Messaging GCM API Key
      define("GOOGLE_API_KEY", "MY_KEY");       
      $headers = array(
          'Authorization: key=' . GOOGLE_API_KEY,
          'Content-Type: application/json'
      );
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_POST, true);
      curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
      $result = curl_exec($ch);             
      if ($result === FALSE) {
          die('Curl failed: ' . curl_error($ch));
      }
      curl_close($ch);
      return $result;
  }
  ?&gt;
  &lt;?php
  //this block is to post message to GCM on-click
  $pushStatus = "";   
  if ( ! empty($_GET["push"])) { 
      $gcmRegID  = file_get_contents("GCMRegId.txt");
      $pushMessage = $_POST["message"];   
      if (isset($gcmRegID) &amp;&amp; isset($pushMessage)) {      
          $gcmRegIds = array($gcmRegID);
          $message = array("m" =&gt; $pushMessage);  
          $pushStatus = sendPushNotificationToGCM($gcmRegIds, $message);
      }       
  }
  //this block is to receive the GCM regId from external (mobile apps)
  if ( ! empty($_GET["shareRegId"])) {
      $gcmRegID  = $_POST["regId"]; 
      file_put_contents("GCMRegId.txt",$gcmRegID);
      echo "Ok!";
      exit;
  }   
  ?&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Google Cloud Messaging (GCM) Server in PHP&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;h1&gt;Google Cloud Messaging (GCM) Server in PHP&lt;/h1&gt; 
          &lt;form method="post"   action="gcm.php/?push=1"&gt;                                              
              &lt;div&gt;                                
                  &lt;textarea rows="2" name="message" cols="23" placeholder="Message to transmit via   GCM"&gt;&lt;/textarea&gt;
              &lt;/div&gt;
              &lt;div&gt;&lt;input type="submit"  value="Send Push Notification via GCM" /&gt;&lt;/div&gt;
          &lt;/form&gt;
          &lt;p&gt;&lt;h3&gt;&lt;?php echo $pushStatus; ?&gt;&lt;/h3&gt;&lt;/p&gt;        
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Please tell me how do I store multiple device registration ids in <em>GCMRegid.txt</em> and send notifications to each of the registered device</p>