PHP code example of vakata / http

1. Go to this page and download the library: Download vakata/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/ */

    

vakata / http example snippets

 php
// REQUEST extras
// create a request instance from the current client data
$req = \vakata\http\Request::fromGlobals();
// now you can inspect properties
$req->getQuery('asdf'); // get the "asdf" GET parameter value
$req->getCookie('sessid'); // get the "sessid" cookie value
$req->getPost('pass'); // get the "pass" POST parameter value
$req->getPrefferedResponseLanguage(); // get the preffered response language
// if a parameter is missing a default you pass in can be returned
$req->getQuery('missing', 'default'); // now $a contains "default"
// return values can also be filtered (all filters are listed in the docs)
$req->getPost('user_id', null, 'int');
// you can also get the whole array of parameters
$all = $req->getPost();

// URI extras
$req->getUri()->getSegment(0);
$req->getUri()->linkTo('some/path', [ 'get_param' => 'value' ]);

// RESPONSE extras
$res = new \vakata\http\Response();
$res = $res->expireCookie('sessid');
if ($res->hasCache()) {
    $res = $res->cacheUntil('+7 days');
}
$res = $res->setContentTypeByExtension('json');