title: Android phonegap send push notification using Google Cloud Messaging using php
body: <p>I have developed the android application in cordova 3.4 now I want to get the automatic notification to their mobile. For this I refer websites as below</p>
  
  <ul>
  <li><a href="http://devgirl.org/2013/07/17/tutorial-implement-push-notifications-in-your-phonegap-application/" rel="nofollow">http://devgirl.org/2013/07/17/tutorial-implement-push-notifications-in-your-phonegap-application/</a></li>
  <li><a href="http://devgirl.org/2012/10/25/tutorial-android-push-notifications-with-phonegap/" rel="nofollow">http://devgirl.org/2012/10/25/tutorial-android-push-notifications-with-phonegap/</a></li>
  <li><a href="https://github.com/hollyschinsky/PushNotificationSample30/tree/master/platforms/android" rel="nofollow">https://github.com/hollyschinsky/PushNotificationSample30/tree/master/platforms/android</a></li>
  </ul>
  
  <p>I read all above links then did all stuff they told like create project on google cloud messaging , get the project id , create server key (In textbox I given my private server IP) then API Key, I also have registration id device and I wrote code in php for sending push notification to my device but it is giving me "<strong>unauthorised Error 404</strong>" </p>
  
  <p>my code is as below</p>
  
  <pre><code>    define( 'API_ACCESS_KEY', 'my api key' );
  
      //$registrationIds = array( $_GET['id'] );
      $registrationIds = array($id);
      //var_dump($registrationIds);die;
      //prep the bundle
      $msg = array
      (
              'message'       =&gt; 'New Jobs is updated',
              'title'         =&gt; 'get the job in cad',
              'subtitle'      =&gt; 'get the job in cad',
              'tickerText'    =&gt; 'Ticker text here...Ticker text here...Ticker text here',
              'vibrate'   =&gt; 1,
              'sound'     =&gt; 1
      );
  
      $fields = array
      (
              'registration_ids'  =&gt; $registrationIds,
              'data'              =&gt; $msg
      );
  
      $headers = array
      (
              'Authorization: key=' . API_ACCESS_KEY,
              'Content-Type: application/json'
      );
  
      $ch = curl_init();
      curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
      curl_setopt( $ch,CURLOPT_POST, true );
      curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
      curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
      curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
      curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
      $result = curl_exec($ch );
      curl_close( $ch );
  
      echo $result;
  </code></pre>
  
  <p>I just hit url and send the registration id of device to the my php page but this page give me the error <strong>unauthorised Error 401</strong>. </p>
  
  <p><strong>Que.1.</strong> Is this possible to send the push notification from php which is hosted on private server?</p>
  
  <p><strong>Que.2</strong> Is device registration id compulsory for sending push notification to those user they installed the apps?</p>
  
  <p>Please anybody help me how to solve this above error and if anybody have another solution then tell me. I tried from yesterday but not achieve my goal so please help me.</p>