TABLE OF CONTENTS
DOWNLOAD & INSTALLATION
First, the download links for the module, and also “installation instructions”.
LICENSE & DOWNLOAD
Core Boxx is released under the MIT License. You are free to use it for personal and commercial projects, and modify it as you see fit. On the condition that the software is provided “as-is”. There are no warranties provided and “no strings attached”. Code Boxx and the authors are not liable for any claims, damages, or liabilities.
INSTALLATION
- Copy/unzip this module into your existing Core Boxx project folder.
- Access
http://your-site.com/install/push
, this will automatically:- Import
lib/SQL-WebPush.sql
into your database. - Generate the VAPID private/public keys, update
lib/CORE-Config.php
. - Delete
PAGE-install-push.php
itself.
- Import
- After installation, access
http://your-site.com/push
for the demo page. - If you have installed the admin panel, there is also an admin page at
http://your-site.com/admin/push
.
SORRY FOR THE ADS...
But someone has to pay the bills, and sponsors are paying for it. I insist on not turning Code Boxx into a "paid scripts" business, and I don't "block people with Adblock". Every little bit of support helps.
Buy Me A Coffee Code Boxx eBooks
NOTES
https://
is required for push notifications to work properly,http://localhost/
is an exception for testing.- Make sure that the OpenSSL extension is installed and enabled in PHP.
- Windows users, if you are still getting an “unable to generate key” error:
- Start > Search for “system environment” > “Edit the system environment variables” > “Environment variables”.
- Add a new system variable called
OPENSSL_CONF
and point it to theopenssl.cnf
file. By default, it is located atxampp\php\extras\openssl\openssl.cnf
.
FILES LIST
LIBRARIES
lib/webpush/
PHP Web Push By Minishlink.lib/LIB-Push.php
Web Push library.
API
lib/API-Push.php
Web Push API.
ASSETS & PAGES
pages/PAGE-push.php
Demo page.assets/PAGE-push.js
Demo page Javascript.pages/ADM-push.php
Push notification admin page.assets/ADM-push.php
Admin page Javascript.
DATABASE REFERENCE
There is only one table to store the “subscribed web push endpoints”. Feel free to add more fields as required – Maybe tie this to the users table.
WEB PUSH SUBSCRIBERS TABLE
Field | Description |
endpoint |
Primary key. |
user_id |
Foreign key. |
data |
JSON encoded subscriber object. |
LIBRARY REFERENCE
Lastly, the list of library functions and API endpoints.
WEB PUSH LIBRARY FUNCTIONS
Save a subscriber. If the user has signed it, this will automatically tie in the user ID from the session.
$endpoint
String, endpoint URL.$sub
String, JSON encoded subscriber object.
Delete subscriber.
$endpoint
String, endpoint URL.
Send a push notification to all subscribers.
$title
String, title of message.$body
String, text.$icon
String, URL of icon.$image
String, URL of background image.$uid
Int, optional userID.
// SEND TO ALL
$_CORE->Push->send("TITLE", "MESSAGE", "ICON.PNG", "BANNER.PNG");
// SEND TO SPECIFIED USER
$_CORE->Push->send("TITLE", "MESSAGE", "ICON.PNG", "BANNER.PNG", 123);
WEB PUSH API FUNCTIONS
Save subscriber.
$_POST["endpoint"]
String, endpoint URL.$_POST["sub"]
String, JSON encoded subscriber object.
Delete a subscriber.
$_POST["endpoint"]
String, endpoint URL.
Send a push notification.
$_POST["title"]
String, title of message.$_POST["body"]
String, text.$_POST["icon"]
String, URL of icon.$_POST["image"]
String, URL of background image.
hello there
am new to all of this so peer with me
where should i find the PUBLIC-KEY & SECRET-KEY
or should i generate it by my self.
and how ?
As “Installation” above – Access
http://site.com/push/1
to generate the keys, copy them intolib/CORE-Config.php
.