PHP Messaging Service

New Messaging Session

Start new messaging session »


View Messaging Session

View an existing messaging session:


Quick Start

Here is an easy example of how to push an event message:
<?php
// set your message
$message = array(
    'id' => 'e4fe82c4eabafda8a0f71f919dfb5340', // example pmessaging session ID
    'event' => 'My Event', // event name
    'message' => 'My test message' // message
);

// push your message to server
$r = file_get_contents('http://www.shayanderson.com/pmessaging/', false, stream_context_create(array(
    'http' => array(
        'method' => 'POST',
        'header' => 'Content-type: application/x-www-form-urlencoded',
        'content' => http_build_query($message)
    )
)));

// display server results (optional)
echo 'Results: ' . $r;

Or, you can use this function to push messages to the pmessaging server:
<?php
/**
 * Push pmessaging session event message
 *
 * @author Shay Anderson 07.13
 * @link http://www.shayanderson.com/pmessaging/
 *
 * @param string $id (pmessaging session ID)
 * @param string $event (event name)
 * @param string $message
 * @param string $ip (optional, only allow messages from specific IP address)
 * @return string (push server response)
 */
function pmessaging($id, $event, $message, $ip = '')
{
    if(strlen($ip) > 0 && isset($_SERVER['REMOTE_ADDR']))
    {
        if(strcasecmp($_SERVER['REMOTE_ADDR'], $ip) != 0) // invalid IP
        {
            return 'Invalid IP address';
        }
    }

    return file_get_contents('http://www.shayanderson.com/pmessaging/', false, stream_context_create(array(
        'http' => array(
            'method' => 'POST',
            'header' => 'Content-type: application/x-www-form-urlencoded',
            'content' => http_build_query(array(
                'id' => $id,
                'event' => $event,
                'message' => $message
            ))
        )
    )));
}

// push message example
$results = pmessaging('e4fe82c4eabafda8a0f71f919dfb5340', 'My Event', 'My test message');

// display server results (optional)
echo 'Results: ' . $results;

// OR push message example with IP address restriction (will only push messages if client IP matches specific IP)
$results = pmessaging('e4fe82c4eabafda8a0f71f919dfb5340', 'My Event', 'My test message', '99.55.180.34');

// display server results (optional)
echo 'Results: ' . $results;



Note: all session messages expire 5 days after they are created, only 60 message pushes allowed per minute

Copyright © 2019 ShayAnderson.com