<?php
$xip = $_SERVER["REMOTE_ADDR"];
$xnome = $_SERVER["HTTP_USER_AGENT"];
$xhora = date('d/m/Y h:i:s');
$xmessage = "$xhora \n Server: $xnome \n IP: $xip ";
// Replace with real GCM browser / server API key from Google APIs
$apiKey = "xxxxxx";
// Replace with real client registration IDs, most likely stored in your database
// Payload data to be sent
$id_cliente = "APA91bEWmyg9WMLQHllaiTGaEIFmpgH606c7G3tPWzqinmKzJDupaPCFxkulkc9xzLpxlRJT39SFTUgM3IE8qdJ3UE0ZnV-LwVBLgPHlpu_F7KmWyPEKLSI";
$xdata = array( 'message' => $xmessage );
// Set request URL to GCM endpoint
$url = 'https://gcm-http.googleapis.com/gcm/send';
// Set POST variables (device IDs and payload)
$fields = array(
'to' => $id_cliente,
'data' => $xdata,
);
// Set request headers (authentication and payload type)
$headers = array(
'Authorization:key=' . $apiKey,
'Content-Type: application/json'
);
// Open connection
$ch = curl_init(); // Set the url
curl_setopt( $ch, CURLOPT_URL, $url ); // Set request method to POST
curl_setopt( $ch, CURLOPT_POST, true ); // Set custom headers
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers); // Get response back as string
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); // Set post data
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) ); // Send the request
$result = curl_exec($ch);
// Close connection
curl_close($ch);
// Debug GCM response
echo $result;
?>