Send push notification using javaScript and PHP

  Рет қаралды 29,353

benixal

benixal

Күн бұрын

Пікірлер: 94
@twoxim
@twoxim 5 ай бұрын
One of the best instructional videos, and I've watched 1000s. Easy to follow and understand! Keep up the great work!!!
@sebaszwarc
@sebaszwarc 7 ай бұрын
ok, the reason navigator is undefined is because notification works only with SSL environment - author didn't mention that at all and because he is using localhost it's even more confusing because you cannot setup https on localhost - certbot will complain as this is not a domain.
@genesaretjohnes5732
@genesaretjohnes5732 Ай бұрын
on mine it works. i think some web apis that need secure context are able to be tested if we use localhost.
@nicholasosinski4097
@nicholasosinski4097 Жыл бұрын
I tried so many guides for how to do this and yours worked... the first time! Thank you so much for the video and for the source code. Thank you!
@benixal
@benixal Жыл бұрын
Thanks, Nicholas! Glad it worked for you!
@nicholasosinski4097
@nicholasosinski4097 Жыл бұрын
I don't suppose you have an example for queueNotification & flush? Thanks again!@@benixal
@nicholasosinski4097
@nicholasosinski4097 Жыл бұрын
Never mind ...I figured it out. Thank you so much, again! 😀
@sebaszwarc
@sebaszwarc 7 ай бұрын
Problem is it's not working
@andrejhohnjec4106
@andrejhohnjec4106 7 ай бұрын
Like watching Bob Ross for coding. Excellent!
@benixal
@benixal 7 ай бұрын
Glad you enjoyed it! Thanks for the kind words!
@RuebenTijani
@RuebenTijani Ай бұрын
😂 push notif. The laziness to type out full words gets me too 😂😂
@benixal
@benixal Ай бұрын
😂✌️
@smitshah3377
@smitshah3377 23 күн бұрын
Great video. For some reason, the notification "icon" is not showing up along with the notification. I have added it as a part of the payload but have had no luck. Any idea?
@jimpannell2035
@jimpannell2035 11 ай бұрын
Thanks for this Ben - I've found it extremely helpful 🙏
@benixal
@benixal 11 ай бұрын
Glad it was helpful! :)
@matrixco5579
@matrixco5579 Сағат бұрын
Super, thank you 👍🏻🙂
@wildanshalahuddin3824
@wildanshalahuddin3824 10 ай бұрын
i'v successed implement your code in plain php, but when i use codeigniter 3, why i cant get the endpoint in the console.log ? its just blank, not error, just blank. Like something block this code "then((subscription)" in the codeigniter view, Can you help me ?
@benixal
@benixal 10 ай бұрын
Make sure that the Service Worker is registered: (06:11) and I checked this with CodeIgniter 3, and I was able to get the subscription data: github.com/benixal/CodeIgniter-3-pushManager-subscription-example
@GiaMisseri
@GiaMisseri 3 ай бұрын
I can get this working on desktop browsers, but the subscription data is not being generated on iOS for me to save... help please?
@lucapagura9873
@lucapagura9873 9 күн бұрын
Thank you so much you’re an amazing friend But does it work on mobile like android and iOS
@Coder-j1p
@Coder-j1p 20 күн бұрын
Mention : If you're using the localhost you can't able to subscribe the client because the API support only https request , since localhost runs in http it will not wok
@vassilismatragos3043
@vassilismatragos3043 5 ай бұрын
Thanks for this Ben!
@marjaybumalod2583
@marjaybumalod2583 7 ай бұрын
how to fix this " Uncaught RuntimeException: Unable to create the key in C:\xampp\htdocs\push_notification\vendor\web-token\jwt-library\Core\Util\ECKey.php:98" ?
@benixal
@benixal 7 ай бұрын
The error 'Unable to create the key in ....\ECKey.php' is likely because OpenSSL isn't turned on. To fix this in XAMPP: Open the php.ini file. Look for ;extension=openssl. Take out the semicolon before it. Save and restart XAMPP. If you don't have OpenSSL, you can use a website to make VAPID keys. Just search "generate VAPID keys." But remember, this is mainly for practice, not real projects
@marjaybumalod2583
@marjaybumalod2583 7 ай бұрын
@@benixal OpenSSL is enabledPHP Fatal error: Uncaught RuntimeException: Unable to create the key in C:\xampp\htdocs\push_notification\vendor\web-token\jwt-library\Core\Util\ECKey.php:98 Here is the another error
@LeguizChristianA.IT-31WEBAPPDE
@LeguizChristianA.IT-31WEBAPPDE Жыл бұрын
is that ok to use only the first part of the video where you not using a library
@HoneyBee-kj3db
@HoneyBee-kj3db 10 ай бұрын
Where should I put each file if I use CodeIgniter 4?
@sampahemmanuel2643
@sampahemmanuel2643 Жыл бұрын
Exactly what I needed. Thanks
@benixal
@benixal Жыл бұрын
You're welcome!
@pingxtratech
@pingxtratech 6 ай бұрын
This is so good. Thank you. I'd like to ask, the notification will only work while the browser is opened yes? Is there a workaround for sending notifications while the browser is closed?
@benixal
@benixal 6 ай бұрын
You're welcome, thanks for your comment, Notifications will be received if the browser is fouced or in the background, (even if your webpage is not opened). On mobile devices: browsers are usually running in the background, so notifications will usually be received. However, on desktops, if the user completely closes the browser, notifications won't be received and they'll receive them immediately upon reopening the browser (there's no need to open your website, just run the browser)
@oriamergi5445
@oriamergi5445 Жыл бұрын
Thanks for the tutorial! I'm stuck in getting the end point after creating the "enableNotif" button. The promise isn't resolved. Up until that point we only used the backend to create public & private keys which we pasted (only the public) in "applicationServerKey" right?
@benixal
@benixal Жыл бұрын
You're welcome! Yes, use the public key for the applicationServerKey . and please provide more details about the error you are getting in the console.
@AmarSingh-e6u5r
@AmarSingh-e6u5r 10 ай бұрын
in my case .then((subscription)=> { console.log(JSON.stringify(subscription)); }); i am not able to see subscription
@caseysky102
@caseysky102 4 ай бұрын
same here
@falinhares
@falinhares Жыл бұрын
I am getting an error when going for the application test: Cannot read properties of undefined (reading 'showNotification') on line event.waitUntil(self.registration.showNotification(notification.title, {...
@falinhares
@falinhares Жыл бұрын
Found a type and corrected, but you have to click to update the service. It doesn't update by itself...
@benixal
@benixal Жыл бұрын
That's due to browser caching. add a unique random query parameter when registering the service worker each time you update it : navigator.serviceWorker.register('sw.js?v=2') or navigator.serviceWorker.register('sw.js?v=' + Math.random())
@Andy-zr8pw
@Andy-zr8pw Жыл бұрын
if my project use php v 7.4, what it is work ?
@benixal
@benixal Жыл бұрын
Yes , but to install `minishlink/web-push` (09:38) ... based on the README from github.com/web-push-libs/web-push-php, ``` PHP 5.6 or HHVM: v1.x PHP 7.0: v2.x PHP 7.1: v3.x-v5.x PHP 7.2: v6.x PHP 7.3 7.4: v7.x ``` you should install version 7.x for PHP 7.4 compatibility. Here's the command to install it: composer require minishlink/web-push:^7.0
@Andy-zr8pw
@Andy-zr8pw Жыл бұрын
thanks you @@benixal
@nishants3967
@nishants3967 Жыл бұрын
Hi Ben, how do I do with SSE server in Node.js, and PHP pages (pre-render) consumes this SSE events. I wrote few snippets but its not working in onmessage. Help appreciated. Thanks.
@benixal
@benixal Жыл бұрын
Hi Nishant , sorry not familiar with that , thanks for your comment.
@nishants3967
@nishants3967 Жыл бұрын
@@benixal No issue. :)
@philippeachache4600
@philippeachache4600 9 ай бұрын
problem: I m stuck with the file send.php about [reason:protected] =>curl error 60, is there a issue to solve it easily
@benixal
@benixal 9 ай бұрын
Check this out: github.com/web-push-libs/web-push-php/issues/93#issuecomment-421913383
@benixal
@benixal 9 ай бұрын
change this line: $webPush = new WebPush($auth); to this: $webPush = new Minishlink\WebPush\WebPush($auth, [], 30, ['verify' => false]);
@philippeachache4600
@philippeachache4600 9 ай бұрын
@@benixal You 're great, man!
@fonnets
@fonnets Жыл бұрын
Hi Ben, after successfully testing everything locally (Mac, MAMP and domain localhost) I tried to test the push notification using an aws ec2 instance and a domain with ssl certificates, but the push notification doesn't arrive... Printing the notification response looks ok, so it's not clear what's stopping the notification from arriving. I have tried with Chrome, Safari and Firefox. My server side stack is ubuntu 22 / apache2 / php 8.1. Do you have any idea? Thanks
@benixal
@benixal Жыл бұрын
Hi there! Thanks for your message , Sorry, I'm not familiar with AWS EC2 instances. Consider asking on AWS forums or Stack Overflow for help. Best of luck!
@fonnets
@fonnets Жыл бұрын
I thought they were problems for notifications from remote servers, since initially only locally it worked perfectly. I did various tests, even with serverless php services, then I tried and tried again, and now I can say that it also works as a remote server with a domain with ssl certificates. It works really well! Thanks again Ben!
@benixal
@benixal Жыл бұрын
You're welcome!
@lwiimbokasweshi
@lwiimbokasweshi 3 ай бұрын
Excellent video
@sampahemmanuel2643
@sampahemmanuel2643 Жыл бұрын
Hi Beni, please how do I position the notification at the bottom right of the screen when the browser is closed or not
@benixal
@benixal Жыл бұрын
No, you can't control the position of browser push notifications. They appear according to the browser's default settings.
@sampahemmanuel2643
@sampahemmanuel2643 Жыл бұрын
Hi Beni, assuming I host my PHP app on Digital Ocean or a Shared Server, can the push notifications still work. Thank you
@benixal
@benixal Жыл бұрын
Hi Sampah, according to the README (github.com/web-push-libs/web-push-php#readme), if your hosting provider supports mbstring, curl, and openssl, and you're using PHP 8, 7, or even 5.6, then you can definitely use the web-push-php library for push notifications.
@abdulhameednabhan5595
@abdulhameednabhan5595 Жыл бұрын
What should I put after the word send in link? server kay from fairbase messaging token?
@benixal
@benixal Жыл бұрын
Sorry, but I did not understand your question Could you please clarify your question or let me know the specific time stamp in the video you're referring to?
@basically_basic
@basically_basic 3 ай бұрын
I don't have autoload.php file
@fonnets
@fonnets Жыл бұрын
Hi, the tutorial is very clear and complete! I managed to replicate the example and everything works. However I don't understand how to manage subscriptions, because to send a notification I have to insert the json of the subscription into the function. This example works with only one browser but if I have to send notifications to multiple browsers do I have to keep all subscriptions and send each one? Thank you
@benixal
@benixal Жыл бұрын
Hi, I'm glad the tutorial was helpful. Yes, to send notifications to multiple browsers, you should store all subscription data in your database and then send notifications to each one you want. But if the number of subscriptions is high For example, you want to send a group notification to 10,000 people It is better to do this on a scheduled basis, for example, once every few seconds .. or use several servers and networks But if the number is much more than this, it is better to use other services such as FCM that allows you to send push notification to very big group of subscriptions.
@fonnets
@fonnets Жыл бұрын
Hi Ben! Now is all clear! Thank you!@@benixal
@bst-football
@bst-football Жыл бұрын
@@benixal hi what is FCM?
@meirbek241
@meirbek241 6 ай бұрын
​@@benixal Hello, Ben. Thank you for the great tutorial. Do you know where can I read about limitations in terms of number of people for sending push notifications using current approach? For example if I want to send push notifications to around 100 users (single notification to a single device) on a daily basis, will current approach work properly?
@geplaksisilla2742
@geplaksisilla2742 4 ай бұрын
@@benixal Dear Benixal! Very useful tutorial, thank you so much! Can you write a sample how can i send more then one subscription?
@benitocanfora7667
@benitocanfora7667 Жыл бұрын
Great video, thank you :)
@benixal
@benixal Жыл бұрын
You are welcome! Glad you liked it!
@FabianD1991
@FabianD1991 Жыл бұрын
Will these notifications be displayed on the mobile? At least with the browser in the background. Thanks!
@benixal
@benixal Жыл бұрын
Absolutely! Notifications will appear on mobile devices, even if the browser is in the background. Thanks for your question!
@fonnets
@fonnets Жыл бұрын
I tested notifications with iPhone (iOS), it works great! You just need to add web apps to the home screen from Safari first.
@iloveyou-kd2lf
@iloveyou-kd2lf Жыл бұрын
7:03 I cliked push button. but it is not showing popup. Why?
@benixal
@benixal Жыл бұрын
Check the console logs.
@diegovillafane6313
@diegovillafane6313 Жыл бұрын
Hi Beni, great content, can I ask you, are you runing the page in a live server or what are you doing to run it?
@diegovillafane6313
@diegovillafane6313 Жыл бұрын
I used live server so it's ok, THANKS A LOT!!!
@benixal
@benixal Жыл бұрын
You're welcome! Thanks for your comment. In the video, I used Apache web server (locally) on Ubuntu. However, you can run the page on any web server of your choice
@zenoxgaming3837
@zenoxgaming3837 10 ай бұрын
Thanks😁❤❤
@benixal
@benixal 10 ай бұрын
You're welcome! 😊
@HeryPurnama
@HeryPurnama 8 ай бұрын
Thank u so much
@benixal
@benixal 8 ай бұрын
you're welcome.
@sebaszwarc
@sebaszwarc 7 ай бұрын
I was expecting to find proper tutorials but yours has errors - Cannot read properties of undefined (reading 'register'). navigator is undefined anywhere. how can you post code without checking
@benixal
@benixal 7 ай бұрын
Thanks for letting me know! Could you please tell me which browser you were using when you encountered the error?
@bamcatiloc5735
@bamcatiloc5735 8 ай бұрын
It will work in localhost?
@benixal
@benixal 8 ай бұрын
Yes.
@bamcatiloc5735
@bamcatiloc5735 8 ай бұрын
Thanks bro
@abdulhameednabhan5595
@abdulhameednabhan5595 Жыл бұрын
First of all, I would like to thank you for this wonderful content. Please help me. I am a beginner First, I had problems when generating the key, so I used the same keys that you used, I mean the keys that we generate with php, does this affect? This is the error Fatal error: Uncaught RuntimeException: Unable to create the key in D:\xampp\htdocs\testno\vendor\web-token\jwt-core\Util\ECKey.php:98 Stack trace: #0 D:\xampp\htdocs\ testno\vendor\web-token\jwt-core\Util\ECKey.php(72): Jose\Component\Core\Util\ECKey::createECKeyUsingOpenSSL('P-256') #1 D:\xampp\htdocs\testno \vendor\web-token\jwt-key-mgmt\JWKFactory.php(69): Jose\Component\Core\Util\ECKey::createECKey('P-256', Array) #2 D:\xampp\htdocs\ testno\vendor\minishlink\web-push\src\VAPID.php(165): Jose\Component\KeyManagement\JWKFactory::createECKey('P-256') #3 D:\xampp\htdocs\testno\VAPID.php (6): Minishlink\WebPush\VAPID::createVapidKeys() #4 {main} thrown in D:\xampp\htdocs\testno\vendor\web-token\jwt-core\Util\ECKey.php on line 98 .. ..... My second question is the value here, where should I get it from? For information, I am a Firebase subscriber I mean the value in the link... $report = $webPush->sendOneNotification( Subscription::create(json_decode('{"endpoint":"fcm.googleapis.com/fcm/send/eOmO_2Z-nHA:APA91bHDoFG8hTpuf11C9t_rVP2IOIOcpDimDLF06DYI9NtRPnQlpRN89KeLP2rl6w8C7WryiEPzkCg3XBwQxm hfL36JNMKGdtNSwd4UegS-7sByuGlYjg6FubHASYrrHVcTfefZaV9W","expirationTime":null,"keys":{"p256dh ":"BNBaksmindsZK9u_mghq-Omb1_9bN-hJVP8KjLWB6mlHPf_R3JLmyd-0LwYBGErAjItB2Pex6bAKYFFR_gDdYpo","auth":"H9M9HgHX4a3xmcChKQNWFA"}}',true)) , '{"title":"Hi from php" , "body":"php is amazing!" , "url":"./?message=123"}', ['TTL' => 5000]); print_r($report);
@benixal
@benixal Жыл бұрын
Thanks for your comment, Abdul Hameed ! The error "Unable to create the key in ....\ECKey.php:98..." usually shows up when a needed tool called OpenSSL isn't turned on. To fix this in XAMPP: Open the php.ini file. Look for ;extension=openssl. Take out the semicolon before it. Save and restart XAMPP. If you don't have OpenSSL, you can use a website to make VAPID keys. Just search "generate VAPID keys." But remember, this is mainly for practice, not real projects For your second question: The subscription data comes when the user runs the enableNotif() function (14:20). The 'fcm' part you noticed is because Chrome uses FCM to send notifications, while if the user uses Firefox , it'll use 'services.mozilla.com'. You don't have to make the subscription data, like the endpoint or anything like that. Just use JSON.stringify (13:20), and then you can send notifications with it (18:08).
@abdulhameednabhan5595
@abdulhameednabhan5595 Жыл бұрын
Please what will this line look like can you write it for me? $report = $webPush->sendOneNotification( Subscription::create(json_decode('{"endpoint":"fcm.googleapis.com/fcm/send/eOmO_2Z-nHA:APA91bHDoFG8hTpuf11C9t_rVP2IOIOcpDimDLF06DYI9NtRPnQlpRN89KeLP2rl6w8C7WryiEPzkCg3XBwQxmhfL36JNMKGdtNSwd4UegS-7sByuGlYjg6FubHASYrrHVcTfefZaV9W","expirationTime":null,"keys":{"p256dh":"BNBaksmindsZK9u_mghq-Omb1_9bN-hJVP8KjLWB6mlHPf_R3JLmyd-0LwYBGErAjItB2Pex6bAKYFFR_gDdYpo","auth":"H9M9HgHX4a3xmcChKQNWFA"}}',true)) , '{"title":"Hi from php" , "body":"php is amazing!" , "url":"./?message=123"}', ['TTL' => 5000]);@@benixal
@carlosgarciamorales1383
@carlosgarciamorales1383 29 күн бұрын
Great video, thank you :)
@carlosgarciamorales1383
@carlosgarciamorales1383 29 күн бұрын
Excellent video
Firebase Send Push Notification JavaScript + PHP
27:22
benixal
Рет қаралды 16 М.
2. Push Notifications with Service worker: Push API + Push Service
13:23
ЛУЧШИЙ ФОКУС + секрет! #shorts
00:12
Роман Magic
Рет қаралды 39 МЛН
Disrespect or Respect 💔❤️
00:27
Thiago Productions
Рет қаралды 40 МЛН
Family Love #funny #sigma
00:16
CRAZY GREAPA
Рет қаралды 62 МЛН
PHP doesn't suck (anymore)
10:48
Aaron Francis
Рет қаралды 210 М.
JWT авторизация. Основы JWT - механизма.
6:45
Хочу вАйти
Рет қаралды 16 М.
Web Push Notifications - End to End implementation
17:24
A shot of code
Рет қаралды 106 М.
How I implement PWA push Notification
14:21
Daily Web Coding
Рет қаралды 10 М.
We Built an App in 24 Hours [No Code]
11:56
Raw Startup
Рет қаралды 443 М.
Sending Push Notifications with Laravel
26:54
benixal
Рет қаралды 11 М.
Push Notifications Using Node.js & Service Worker
29:52
Traversy Media
Рет қаралды 283 М.
How To Send Push Notifications With JavaScript
11:38
Web Dev Simplified
Рет қаралды 352 М.
ЛУЧШИЙ ФОКУС + секрет! #shorts
00:12
Роман Magic
Рет қаралды 39 МЛН