Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Use Firebase Cloud Messaging to Send Push Notification in PHP Application

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 5.32k
    Comment on it

    Using (FCM) Firebase Cloud Messaging you can send the real time notification to the browser in your PHP web application , Using FCM, you can notify a client that new event or other data or mail is available to sync.

     

     

       To send the notification you need to get the FCM Token From User. After you get the token now we will send the notification using following script.

       Note :- You can get the API key after sign up from https://console.firebase.google.com/

     

            // declare the array for notification message
            $param = []; 
            $params['notification']['notification_title'] = 'Title';
            $params['notification']['notification_body'] = 'Body';
            $params['notification']['notification_click_action'] = 'Click Action';
            $params['to'] = "<Firebase Token>"; // use your firebase token here
            $url = 'https://fcm.googleapis.com/fcm/send';
            $fields = json_encode($params);
    
            set the header
            $headers = array(
                'Authorization: key=' . "<your api key>",
                'Content-Type: application/json'
            );
    
            // create the curl request to send the push notification
            $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_POSTFIELDS, $fields);
            $result = curl_exec($ch);
            curl_close($ch);
    

     

    Use Firebase Cloud Messaging to Send Push Notification in PHP Application

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: