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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:31:08+00:00 2026-06-14T05:31:08+00:00

I am fairly new with PHP and I’m stuck on this big time. I

  • 0

I am fairly new with PHP and I’m stuck on this big time.

I am trying to extract the error message “InvalidRegistration” in this instance, which appears to be in an array within an array and then filter and act upon it in my PHP server.

Note that the error array may have a greater depth than 1 on multicast messages to multiple regId’s.

Any help will be greatly appreciated, thanks!


Dumped GCM server response:

object(stdClass)#3 (5) { [“multicast_id”]=> int(6225919148914620552) [“success”]=> int(0) [“failure”]=> int(1) [“canonical_ids”]=> int(0) [“results”]=> array(1) { [0]=> object(stdClass)#4 (1) { [“error”]=> string(19) “InvalidRegistration” } } }

Send message code:

    $dbf = new push_db_functions();  

    // a row id which contains an intentionally bad regId
    // to trigger the error from 'test' mySql database
    $id = '19'; 

    $result = $dbf->sendMessage($id);

    // dump GCM server response  
    $obj2 = json_decode($result);  
    var_dump($obj2);

   // TODO: (Question Subject)
   // how to extract and test for if('failure' == 1) { ...?
   // and then how to extract 'error' message so I can act upon it appropriately?

Send message helper code:

public function sendMessage($id) {
    $sqlquery = "SELECT regid FROM test WHERE Id = '$id'";
    $results = mysql_query($sqlquery);
    $processed = mysql_fetch_row($results);
    $url = 'https://android.googleapis.com/gcm/send';
    $apiKey = "my api key";
    $message = "Hello World";
    $fields = array('registration_ids' => $processed, '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));
    // execute post
    $response = curl_exec($ch); 
    curl_close($ch);
    return $response;
}

  • 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-14T05:31:09+00:00Added an answer on June 14, 2026 at 5:31 am

    To just grab the error code given, you should be able to use

    $obj2->results[0]->error;
    

    But if you want to do it flexibly, you may wish to do something more along the lines of…

    $errors = array();
    
    if( !empty($obj2->results) ) {
        foreach( $obj2->results as $result ) {
            $error = $result->error;
            // Do whatever you want with the error here. 
            // In this instance, I'm just putting it into a fancy array
            $errors[] = $error;
        }
    }
    
    // $errors = array( [0] => 'InvalidRegistration' );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am fairly new to PHP and Codeigniter so im sure this will be
I'm fairly new to PHP so am not sure how to do this. I
I'm trying to parse a quite large XML-sheet with PHP, but I'm fairly new
I'm fairly new to php and I am trying to figure how do I
I am fairly new to PHP and MySQL and am trying to write a
Notes: I'm still fairly new to php This login form seems to work perfectly
i am fairly new to php. I am trying to print out the username
I am fairly new to PHP. I have a function which checks the cost
I've fairly new to PHP MVC and I'm not 100% sold I'm doing this
I'm fairly new to PHP and the setting of custom error handlers, but I

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.