<?php
function sendGCM($UserID, $message) {
$databasehost = "...";
$databasename = "...";
$databaseusername = "...";
$databasepassword = "...";
$db = mysqli_connect($databasehost,$databaseusername,$databasepassword,$databasename);
if(!$db)
{
exit("Fehler: " .mysqli_connect_error());
}
// $abfrage = "SELECT id FROM c2dm WHERE name LIKE 'lgandi'";
$abfrage = "SELECT id FROM c2dm WHERE name LIKE '$UserID'";
$ergebnis = mysqli_query($db, $abfrage);
$row = mysqli_fetch_object($ergebnis);
// Replace with real BROWSER API key from Google APIs
$apiKey = "xyzXYZ";
// Replace with real client registration IDs
$registrationIDs = array( $row->id );
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array( "data" => $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_SSL_VERIFYPEER, false);
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);
}
?>
<?php
$rcv = $_Get["name"];
$msg = $_Get["msg"];
sendGCM($rcv, $msg);
?>