Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8719213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:44:22+00:00 2026-06-13T06:44:22+00:00

I am working on a php script to send the notification to the CGM

  • 0

I am working on a php script to send the notification to the CGM server and I am working from this example:

public function send_notification($registatoin_ids, $message) {
// include config
include_once ‘./config.php’;

    // Set POST variables
    $url = 'https://android.googleapis.com/gcm/send';

    $fields = array(
        'registration_ids' => $registatoin_ids,
        'data' => $message,
    );

    $headers = array(
        'Authorization: key=' . GOOGLE_API_KEY,
        'Content-Type: application/json'
    );
    // Open connection
    $ch = curl_init();

    // Set the url, number of POST vars, POST data
    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Disabling SSL Certificate support temporarly
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

    // Execute post
    $result = curl_exec($ch);
    if ($result === FALSE) {
        die('Curl failed: ' . curl_error($ch));
    }

    // Close connection
    curl_close($ch);
    echo $result;
}

But I am not certain what the values should be for the variables: CURLOPT_POSTFIELDS , CURLOPT_SSL_VERIFYPEER , CURLOPT_RETURNTRANSFER , CURLOPT_HOST , CURLOPT_URL

Would anyone happen to know what the values for these should be?

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:44:24+00:00Added an answer on June 13, 2026 at 6:44 am

    ” CURLOPT_POSTFIELDS ” this field is required to push number of fields in json encoding format. “CURLOPT_SSL_VERIFYPEER” this field is required if your third party server is HTTPS over SSL. “CURLOPT_RETURNTRANSFER” This field gives you reply from gcm server. “CURLOPT_HOST , CURLOPT_URL” this field is for HOST name and URL you have to define of your third party server.

    That is de code that I have implemented :

    <?php
    $apiKey = "Your Api Key"; 
    $reg_id = array("Your registration ID that we have get from device");
    $registrationIDs = $reg_id;
    
    // Message to be sent
    $message = $_REQUEST['message']; 
    
    // Set POST variables
    $url = 'https://android.googleapis.com/gcm/send';
    $fields = array(
              'registration_ids' => $registrationIDs,
              'data' => array( "message" => $message ),
               );
    $headers = array(
            'Authorization: key=' . $apiKey,
            'Content-Type: application/json'
             );
    
    // Open connection
    $ch = curl_init();
    
    // Set the url, number of POST vars, POST data
    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 ) );
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    //curl_setopt($ch, CURLOPT_POST, true);
    //curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $fields ));
    // Execute post
    $result = curl_exec($ch);
    // Close connection
    curl_close($ch);
    echo $result;
    ?>
    

    As per my experience this links will help you :

    GCM with PHP (Google Cloud Messaging)

    http://www.sherif.mobi/2012/07/gcm-php-push-server.html

    https://groups.google.com/forum/#!topic/android-gcm/hjk5PUYlTp0

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We currently have a working php mail script, this works fine and as we
I'm working on a PHP script that runs a Python script on the server.
What is the best way to send messages from PHP script to Java program
So i'm working on a php script which passes information to a server using
Can a PHP script (which can be working with a MySQL DB) send and/or
I now have a small java script server working correctly, called by: <?php $handle
I am working on php script that may involve a long running task. The
I'm working on a PHP script that compiles a JavaScript framework. Right now I'm
I have the following PHP script with the working (according to JsonViewer ) JSON
I working in Rails and I need to call to an PHP-script. I can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.