File: PNSubscriber.php

Recommend this page to a friend!
  Classes of Stefan Kientzler  >  PHP Web Push Notifications Server  >  PNSubscriber.php  >  Download  
File: PNSubscriber.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Web Push Notifications Server
Queue and push notifications to Web users
Author: By
Last change:
Date: 2 months ago
Size: 908 bytes
 

Contents

Class file image Download
<?php
require_once 'lib/PNServer/PNDataProviderSQLite.php';

use
lib\PNServer\PNDataProviderSQLite;

$result = array();
// only serve POST request containing valid json data
if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
    if (isset(
$_SERVER['CONTENT_TYPE']) && trim(strtolower($_SERVER['CONTENT_TYPE']) == 'application/json')) {
       
// get posted json data
       
if (($strJSON = trim(file_get_contents('php://input'))) === false) {
           
$result['msg'] = 'invalid JSON data!';
        } else {
           
$oDP = new PNDataProviderSQLite();
            if (
$oDP->saveSubscription($strJSON) !== false) {
               
$result['msg'] = 'subscription saved on server!';
            } else {
               
$result['msg'] = 'error saving subscription!';
            }
        }
    } else {
       
$result['msg'] = 'invalid content type!';
    }
} else {
   
$result['msg'] = 'no post request!';
}
// let the service-worker know the result
echo json_encode($result);


For more information send a message to info at phpclasses dot org.