Can't send PUSH notifications with GCM

asfandyar

New Member
I have some code working fine on my localhost, but when I move it all to my server, it doesn't seem to work.My server is behind a firewall so I decided to use a PHP script to use GCM. Again, I tested it all on localhost and it works but on my server, nothing gets sent.Here is my PHP script: \[code\]<?phpinclude('tools.php');// Replace with real BROWSER API key from Google APIs$apiKey = "xxxx";// Replace with real client registration IDs //$registrationIDs = array($_POST['devices']);$registrationIDs = $_POST['devices'];$proxy = 'http://proxy.vmsrv.redbrick.dcu.ie:3128';// Message to be sent$message = $_POST['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 datacurl_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_PROXY, $proxy);// Execute post$result = curl_exec($ch);// Close connectioncurl_close($ch);print_as_json($result);// Report all PHP errorserror_reporting(-1);?>\[/code\]The only output I get in my console after my Java program has called the script is:\[code\][java] DB: Result: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, string given in /var/www/tools.php on line 5[]\[/code\]Is there anyway I can try get some information back to figure out what the problem is???Edittools.php\[code\]<?phpfunction print_as_json($result) { $all = array(); while($r = mysql_fetch_assoc($result)) { $all[] = $r; } echo(json_encode($all));}?>\[/code\]
 
Back
Top