The notification.php
file helps you send notifications to your Firebase clients (Android, Web or iOS) via Firebase HTTPV1 API.
- To use this code, you need
Google Auth Library for PHP
to authenticate your notification requests. - Follow this link to install it on your server.
- To send notification via Firebase, you need a private key file for your service account. You can get it by following this link.
- Once you got service json file, Upload it on your server at some safe path not accessible to public user preferrably in the root directory of your server and rename it to
server.json
. - Edit
notification.php
and replace <user_dir> with your root directory path. - Now in your main PHP code, include
notification.php
, initialize Notification object with your Firebase project id (Which you can get on the Firebase console) and callsendToTopic
method withtopic
,title
andbody
as arguments.sendToTopic
will return true if everything succeeds else it will return false.