PHP code example of simplemehanizm / http

1. Go to this page and download the library: Download simplemehanizm/http library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

simplemehanizm / http example snippets


use SimpleMehanizm\Http\Request;

$request = Request::fromSuperglobals();

use SimpleMehanizm\Http\Request;
use function SimpleMehanizm\Http\get_http_headers;

$request = new Request(
    get: $_GET,
    post: $_POST,
    request: $_REQUEST, 
    headers: get_http_headers($_SERVER),
    cookies: $_COOKIE,
    files: $_FILES,
    server: $_SERVER 
);


use SimpleMehanizm\Http\Request;

$request = Request::fromSuperglobals();

// Check if exists
if($request->hasHeader('content-type'))
{
    $value = $request->header('content-type', 'default-value-when-not-present');
}

// get all headers
$headers = $request->headers();

// Change or inject header
$request->setHeader('accept', 'application/json');


use SimpleMehanizm\Http\Request;

$request = Request::fromSuperglobals();

$input_value = $request->input('key value', 'default value when not found');

use SimpleMehanizm\Http\Request;

$request = Request::fromSuperglobals();

$input_value = $request->get('get_param_name');

use SimpleMehanizm\Http\Request;

$request = Request::fromSuperglobals();

$input_value = $request->get('get_param_name');