Web Push Notifications

The [Web Push Notifications](https://developers.google.com/web/fundamentals/push-notifications) feature enables you to send notification messages to the subscribed users of your web application. Push and notification use different, but complementary, APIs: - [push](https://developer.mozilla.org/en-US/docs/Web/API/Push_API) is invoked when a server supplies information to a service worker - [notification](https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API) is the action of a service worker or web page script showing information to a user
1. Not all browsers support [Push API](https://developer.mozilla.org/en-US/docs/Web/API/Push_API), some browsers (e.g. Safari) do not. See [Browser compatibility](https://developer.mozilla.org/en-US/docs/Web/API/Push_API#browser_compatibility). 2. **Only sites with SSL (i.e. https) will support Web Push Notifications.** 3. The PHP [openssl](https://www.php.net/manual/en/openssl.installation.php) and [gmp](https://www.php.net/manual/en/gmp.installation.php) extensions are required. 4. Push is based on service workers operating in the background. Code only runs when the user interacts with a notification by clicking or closing it. See the [service worker introduction](https://developers.google.com/web/fundamentals/getting-started/primers/service-workers). 5. **By default only administrators can send notifications.**

How to Use

To enable the feature, you need to: - In [PHP Settings](phpsetup.html), under the **General Options** tab, select the **Web Push** tab, then enable the **Use Web Push Notifications** checkbox. ![](images/webpush.png) - Set up the Subscriptions table by clicking **Create Table**. - If you already have a subscription table, select it in the dropdown and click the **[…]** button to set up fields. ![](images/webpush1a.png) - Click **Generate** to generate the VAPID public/private key pair. If you already have valid keys, enter them in **Server public key** and **Server private key** fields. - Optionally enable **Allow anonymous users** to allow unsubscribed visitors.

Receive Notifications

After generation, an **Enable notifications** button will appear at the top right corner of the site once a user logs in. ![](images/webpush1.png) The user can click the button to enable notifications. A dialog will prompt them to **Allow** or **Block**. If **Allow** is clicked, the user will be subscribed. ![](images/webpush2a.png) *Firefox* A subscription record will be added and administrators can send notifications. Users can later disable notifications in their browser settings (**Note:** this is a browser setting, not a site setting). ![](images/webpush2.png) *Firefox* To unsubscribe within the site, the user can click **Disable notifications** at the top right. ![](images/webpush6.png)

Send Notifications

Administrators can go to the Subscriptions table, select users, and click **Send push notifications**. To send to all users, click without selecting. ![](images/webpush3.png) A **Send Push Notifications** dialog appears where the subject and message can be entered. ![](images/webpush4.png) The message will be sent and displayed on the user's machine. ![](images/webpush5.png) *Firefox* **Note:** If you want to customize the **Send Push Notifications** dialog or use your own service worker for handling messages, see [Push event](https://developers.google.com/web/fundamentals/push-notifications/handling-messages) and [Server Events and Client Scripts](customscripts.html#server). Also see [ServiceWorkerRegistration.showNotification()](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification) for notification options.

Send Single Notification by Code

To send a single web push notification to a subscriber by code (e.g. in server events), you can find the subscriber from the Subscriptions table (or view) and then call the `SendWebPushNotification()` function. **Example**

Test HTTPS on localhost with Chrome

Web push notifications require HTTPS. If testing locally, create and install a certificate for your web server and use `https` instead of `http`. - For [XAMPP](https://www.apachefriends.org/index.html), you can use [makecert.bat](https://github.com/xampp-phoenix/xampp/blob/master/apache/makecert.bat) to create a certificate for localhost. - Chrome may warn "Your connection is not private": ![](images/webpush7a.png) *Chrome* Click "Advanced" → "Proceed to localhost (unsafe)" to continue testing. ![](images/webpush7b.png) *Chrome* You may also need to start Chrome with: `--ignore-certificate-errors --unsafely-treat-insecure-origin-as-secure=https://localhost:443` Clicking "Not secure" warning shows details but does not affect testing. Self-signed certificates work for web push. Other browsers, e.g. Firefox, can also be used. ![](images/webpush7.png) *Chrome*


 ©2002-2025 e.World Technology Ltd. All rights reserved.