We help IT Professionals succeed at work.

Web push notification

BR
BR asked
on
134 Views
1 Endorsement
Last Modified: 2019-02-15
Dear Experts,
I have a web site,
I use PHP 7.1.

All my pages are html5 and PHP
I want to send push notification to my web site users.
How can i do that?

Do you use push notification on your web sites?
Which service do you use?
Do you provide the source code?
Thank you
Comment
Watch Question

IT Manager
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
BRDigital Marketing

Author

Commented:
Dear Kimputer, I read the link you sent, and

now I am here. I use PHP.
what should I do now in order to send the push notification?

cURL Command to Send Push
curl --header "Authorization: key=............" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\".......................\"]}"
David FavorFractional CTO
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
As Kimputer suggested, this entire process is complex.

When you ask, "what should I do now in order to send the push notification?"

The answer is either you or someone you hire will start through the above link + implement every step, till you have push notifications working.

This can be a long process, depending on your how much infrastructure you already have setup, your level of coding expertise.

Just jump in and get started. If you get stuck on a specific step, then ask another question about a specific step.

Note: Be sure to go through each step + debug work done so far, to ensure every incremental step works.
David FavorFractional CTO
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Tip: If the above seems daunting...

You can always use an existing service like https://pushcrew.com/ to speed up + simplify your process.
BRDigital Marketing

Author

Commented:
Dear David,

I get this error message:

The request was missing an Authentication Key (FCM Token). Please, refer to section "Authentication" of the FCM documentation, at https://firebase.google.com/docs/cloud-messaging/server.

since I had this error message I add the code to Authentication Key which I get from under firebase Project credentials / Legacy server key.

My code is here:

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://android.googleapis.com/gcm/send",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{\"registration_ids\":[\".......................\"]}",
  CURLOPT_HTTPSHEADER => array(
    "authorization: key=.......................",
	"Authentication Key= ......................",
    "content-type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

Open in new window

I think I'm very close to send push notification... I need your help, thank you
David FavorFractional CTO
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Tip: Use the curl command line command first. Once you get this working, port to using libcurl from PHP.

Cut & Paste the exact "cURL Error #:" message emitted.
BRDigital Marketing

Author

Commented:
the error message is: The request was missing an Authentication Key (FCM Token). Please, refer to section "Authentication" of the FCM documentation, at https://firebase.google.com/docs/cloud-messaging/server.
Error 401
BRDigital Marketing

Author

Commented:
thank you both
Scott FellDeveloper
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2013

Commented:
https://www.experts-exchange.com/questions/29136119/Web-push-notification.html#a42799942

Yes, you will need to use firebase now https://firebase.google.com/docs/cloud-messaging/

There are a couple of options, one is making this sending notifications to the browser.  The disadvantage here is it will require asking permission from the user.  This means part of your application code will be knowing if the user has authorized push in the browser.  The big advantage of this method is you may not need to use a third party service and you are simply sending the notification to the front end https://developers.google.com/web/fundamentals/push-notifications/ 

The overall better experience is going to be using a third party service and it looks like that is what EE does here (See the notifications you get on for the bell or messages at the top right of your screen). Some options are:
https://firebase.google.com/docs/cloud-messaging/server
https://www.twilio.com/notify
https://onesignal.com/webpush
https://azure.microsoft.com/en-us/services/notification-hubs/

Keep in mind there is a difference between pushing notifications to the browser vs keeping the push notification to your app.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.