Skip to content

Instantly share code, notes, and snippets.

@raihan-uddin
Created September 29, 2020 04:33
Show Gist options
  • Save raihan-uddin/d328c5feff76fdea23e8e8206eb42c9c to your computer and use it in GitHub Desktop.
Save raihan-uddin/d328c5feff76fdea23e8e8206eb42c9c to your computer and use it in GitHub Desktop.
PHP FIREBASE PUSH NOTIFICATION
<?php
function sendPushNotification($to = '', $data = array()){
$apiKey = '';
$fields = ['to' => $to, 'notification' => $data];
$headers = ['Authorization: key='.$apiKey, 'Content-Type: application/json'];
$url = 'https://fcm.googleapis.com/fcm.send';
$ch = curl_init();
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_PROXY_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
curl_close();
return json_decode($result, true);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment