As of now GCM only works for chrome and android.
similarly firefox and other browsers has their own api.
Now coming to the question how to implement push notification so that it will work for all common browsers with own back end.
- You need client side script code i.e service worker,refer( Google push notification). Though this remains same for other browsers.
2.after getting endpoint using Ajax save it along with browser name.
3.You need to create back end which has fields for title,message, icon,click URL as per your requirements. now after click on send notification, call a function say send_push(). In this write code for different browsers for example
3.1. for chrome
$headers = array(
'Authorization: key='.$api_key(your gcm key),
'Content-Type: application/json',
);
$msg = array('to'=>'register id saved to your server');
$url = 'https://android.googleapis.com/gcm/send';
$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_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($msg));
$result = curl_exec($ch);
3.2. for mozilla
$headers = array(
'Content-Type: application/json',
'TTL':6000
);
$url = 'https://updates.push.services.mozilla.com/wpush/v1/REGISTER_ID_TO SEND NOTIFICATION_ON';
$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_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
for other browsers please google...