Skip to content

Instantly share code, notes, and snippets.

@bocharsky-bw
Last active August 29, 2015 13:57
Show Gist options
  • Save bocharsky-bw/9600982 to your computer and use it in GitHub Desktop.
Save bocharsky-bw/9600982 to your computer and use it in GitHub Desktop.
<?php
$data = new stdClass();
if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
/* Router */
if (isset($_POST['buy'])) {
$data->success = TRUE;
$data->message = 'Message succesfully sent';
}
/* /Router */
} else {
$data->success = FALSE;
$data->message = 'Error occurred! Method "'. $_SERVER['REQUEST_METHOD'] .'" not allowed.';
header('Status: 405 Method Not Allowed');
}
} else {
$data->success = FALSE;
$data->message = 'Error occurred! Only AJAX requests allowed.';
header('Status: 400 Bad Request');
}
print json_encode($data); die;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment