Skip to content

Instantly share code, notes, and snippets.

@ChicagoDev
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChicagoDev/4e7cc6812ed4f0ea2607 to your computer and use it in GitHub Desktop.
Save ChicagoDev/4e7cc6812ed4f0ea2607 to your computer and use it in GitHub Desktop.
A quick example of communication with JSON over HTTP using PHP
<?php
/**
* Created by PhpStorm.
* User: Blake Gideon
* Date: 3/14/15
* Time: 7:34 PM
*/
$incoming_post = file_get_contents("php://input");
$incoming_post = json_decode($incoming_post, true);
$name = $incoming_post["clientName"];
# json_encode()
$message = "Thanks for posting Mr: $name";
$response = array("RESPONSE" => $message);
$response = json_encode($response);
echo $response;
exit;
//echo $message;
/* REQUEST:
*
* POST /COMP-353-midterm/php_scripts/ajax.php HTTP/1.1
* Content-Type: application/json
* Accept: application/json
* Host: localhost:63342
* Connection: close
* User-Agent: Paw/2.1.1 (Macintosh; OS X/10.10.2) GCDHTTPRequest
* Content-Length: 26
*
* {
* "clientName":"Gideon"
* }
*
*
* ______________________
*
* HTTP/1.1 200 OK
* X-Powered-By: PHP/5.6.2
* Content-type: text/html; charset=UTF-8
* Server: PhpStorm 8.0.3
* Content-Length: 36
*
* {"Thanks for posting Mr: ":"Gideon"}
*
*
*
*
*
*
* */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment