Simple Ajax Chat Test Script
When testing my plugin, Simple Ajax Chat (SAC), I use the following script to save time testing various chat functionality. Posted here in case it’s useful for others. Note this is for the free version of SAC. Enjoy!
SAC Test Script
Note that this script is for SAC (free) version 20160408 and better. For older versions, change simple-ajax-chat-core.php
to simple-ajax-chat.php
on line 23. Without further ado, here is the test script:
$sac_host = $sac_request = $sac_referer = $sac_address = '';
if (isset($_SERVER["HTTP_HOST"])) $sac_host = htmlentities($_SERVER["HTTP_HOST"], ENT_QUOTES, 'UTF-8');
if (isset($_SERVER["REQUEST_URI"])) $sac_request = htmlentities($_SERVER["REQUEST_URI"], ENT_QUOTES, 'UTF-8');
if (isset($_SERVER['HTTP_REFERER'])) $sac_referer = htmlentities($_SERVER['HTTP_REFERER'], ENT_QUOTES, 'UTF-8');
if (isset($_SERVER['REMOTE_ADDR'])) $sac_address = htmlentities($_SERVER['REMOTE_ADDR'], ENT_QUOTES, 'UTF-8');
$sac_chat_url = 'http://' . $sac_host . $sac_request;
$sac_match = preg_match("/$sac_host/i", $sac_referer);
if ($sac_referer == 'http://example.com/chat/') {
$test_email_message =
'Host: ' . $sac_host . "\n" .
'Request: ' . $sac_request . "\n" .
'Referrer: ' . $sac_referer . "\n" .
'IP Address: ' . $sac_address . "\n" .
'Matched: ' . $sac_match . "\n" .
'Verify: ' . strip_tags($_POST['sac_verify']) . "\n" .
'Check: ';
// log or mail..
}
$sac_email = preg_match("/simple-ajax-chat-core.php/i", $sac_request);
if ($sac_email) {
if ((isset($sac_match)) && ($sac_match !== null) && ($sac_match !== 0) && ($sac_match !== '')) {
$match = 'pass';
} else {
$match = 'fail';
}
if (empty($_POST['sac_verify'])) {
$postVerify = 'pass';
} else {
$postVerify = 'fail';
}
if ((isset($sac_referer)) && ($sac_referer !== null) && ($sac_referer !== '')) {
$refPass = 'pass';
} else {
$refPass = 'fail';
}
if (current_user_can('read')) {
$loggedinuser = 'true';
} else {
$loggedinuser = 'false';
}
$test_email_message =
'Host: ' . $sac_host . "\n" .
'Request: ' . $sac_request . "\n" .
'Referrer: ' . $sac_referer . "\n" .
'IP Address: ' . $sac_address . "\n" .
'Matched: ' . $match . "\n" .
'Verify: ' . $postVerify . "\n" .
'Check: ' . $refPass . "\n" .
'LoggedIn: ' . $loggedinuser . "\n" .
'COOKIE: ' . strip_tags($_COOKIE['PHPSESSID']) . "\n" .
'SESSION: ' . strip_tags(session_id());
// log or mail..
}
It’s quick and dirty, but sufficient for on-the-fly testing of chat messages.