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 8353057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:08:55+00:00 2026-06-09T09:08:55+00:00

I want to sent message from my server to phone, by PHP. Here is

  • 0

I want to sent message from my server to phone, by PHP.
Here is my code:

    $apiKey = "AIxxxxxxxxxxxxxxxxxxxx";

    $registrationIDs = array( $c2dmId );

    $url = "https://android.googleapis.com/gcm/send";

    $headers = array( 
                        'Authorization: key='.$apiKey,
                        'Content-Type: application/json'
                    );

    $fields = array(
                    'collapse_key'      => $collapseKey,
                    'data'              => array( 
                        "type"      => $msgType,
                        "extra"     => $msgExtra,
                        "uuid"      => $uuid,
                        "user_id"   => $userId),
                    'registration_ids'  => $registrationIDs,
                    );

    print (json_encode($fields));
    echo "<br/>";

    $ch = curl_init();

    curl_setopt( $ch, CURLOPT_URL, $url );

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

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

    $result = curl_exec($ch);
    $resultInfo = curl_getinfo($ch);

    echo "resultinfo: $resultInfo <br>";
    foreach ($resultInfo as $key => $value) {
        echo "$key => $value <br>";
    }

    curl_close($ch);
    die ("Result: $result");

Where $c2dmId is just registrationId which I send to server from phone. As a result I get (in $result variable):

<HTML>
<HEAD>
<TITLE>Not Found</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Not Found</H1>
<H2>Error 404</H2>
</BODY>
</HTML>

And I don’t know why. Can anyone help? Documentation dosen’t say anything about 404 code, so I really don’t know what is going on.

  • 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-09T09:08:57+00:00Added an answer on June 9, 2026 at 9:08 am

    Oh, I completely forgot about this question, sorry for that. I already find out what was the problem.
    Earlier I used that code which I posted before to send messages via C2DM. I made only a few improvements to adjust it to GCM. And one of variables ($msgExtra) could equal null in some case. It was intended behaviour and with C2DM it worked just fine.
    Unfortunately, when you try to pass null in JSON via GCM you get 404 error, although GCM documentation says nothing about that…
    So code which I posted is good as far as you don’t try to send null.
    Solution of my problem is to replace null value with something like “”.
    And once again – sorry that I post it just now, I completely forgot about this question.

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

Sidebar

Related Questions

i want to sent very large data from Server to client, the server is
I want to send a message from the server to the client and found
I'm struggeling with code from this page: http://www.androidsnippets.com/encrypt-decrypt-between-android-and-php I want to send data from
I want to see the actual commands sent to g++ during a Code::Blocks build.
I want to capture the Ctrl + C ( SIGINT ) signal sent from
i have data that i fetch from an email server i want to eliminate
Here's my scenario. As part of my app when someone is sent a message
I want to create a class that handles Flash-PHP client-server communication. Basically, Flash sends
I want to send SMS using GSM modem's AT-Commands from SQL Server 2008, so
I have the following code that I am using to send a message from

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.