PHP Classes

File: test.php

Recommend this page to a friend!
  Classes of Marco Cesarato   PHP API Database   test.php   Download  
File: test.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: PHP API Database
Provide access to database records via REST API
Author: By
Last change: Reformatted code (php-cs-fixer)

Added code standard,
Added hooks git for code standard,
Fixed parse where on null elements
Date: 4 years ago
Size: 968 bytes
 

Contents

Class file image Download
<?php

header
('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, PATCH');
$method = $_SERVER['REQUEST_METHOD'];

// Parse GET params
$source = $_SERVER['QUERY_STRING'];

parse_str($source, $params);

// Parse POST, PUT, DELETE params
if ($method != 'GET' && $method != 'DELETE') {
   
$source_input = file_get_contents('php://input');
   
parse_str($source_input, $params_input);
   
$params = array_merge($params, $params_input);
}

// Read header Access-Token
if (isset($_SERVER['HTTP_ACCESS_TOKEN'])) {
   
$params['token'] = $_SERVER['HTTP_ACCESS_TOKEN'];
}

$params['__METHOD__'] = $method;

switch (
$method) {
    case
'PUT':
        echo
json_encode($params);
        break;
    case
'POST':
        echo
json_encode($params);
        break;
    case
'GET':
        echo
json_encode($params);
        break;
    default:
        echo
json_encode($params);
        break;
}