1. Go to this page and download the library: Download jason-gao/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/ */
echo $httpRequest->getMethod(); // GET, POST, HEAD, PUT
if ($httpRequest->isMethod('GET')) ...
echo $httpRequest->isSecured() ? 'yes' : 'no';
echo $httpRequest->isAjax() ? 'yes' : 'no';
echo $httpRequest->getRemoteAddress(); // user's IP address
echo $httpRequest->getRemoteHost(); // and its DNS translation
echo $httpRequest->getReferer()->host;
$get = $httpRequest->getQuery(); // array of all URL parameters
$id = $httpRequest->getQuery('id'); // returns GET parameter 'id' (or null)
$post = $httpRequest->getPost(); // array of all POST parameters
$id = $httpRequest->getPost('id'); // returns POST parameter 'id' (or null)
$cookies = $httpRequest->getCookies(); // array of all cookies
$sessId = $httpRequest->getCookie('sess_id'); // returns the cookie (or null)
$files = $httpRequest->getFiles(); // array of all uploaded files
$file = $httpRequest->getFile('avatar'); // returns one file
echo $file->getName(); // name of the file sent by user
echo $file->getSanitizedName(); // the name without dangerous characters
// Header sent by browser: Accept-Language: cs,en-us;q=0.8,en;q=0.5,sl;q=0.3
$langs = array('hu', 'pl', 'en'); // languages supported in application
echo $httpRequest->detectLanguage($langs); // en
$requestFactory = new Nette\Http\RequestFactory;
// remove spaces from path
$requestFactory->addUrlFilter('%20', '', PHP_URL_PATH);
// remove dot, comma or right parenthesis form the end of the URL
$requestFactory->addUrlFilter('[.,)]$');
// clean the path from duplicated slashes (default filter)
$requestFactory->addUrlFilter('/{2,}', '/', PHP_URL_PATH);
// $container is a system container
$container->addService('httpRequest', $requestFactory->createHttpRequest());
// browser cache expires in one hour
$httpResponse->setExpiration('+ 1 hours');
$httpResponse->setHeader('Pragma', 'no-cache');
// or if we want to send the same header more times with different values
$httpResponse->addHeader('Pragma', 'no-cache');