Mecha CMS

Mecha CMS blog and documentation.

Class HTTP

Updated: Sunday, 07 August 2016

HTTP headers.

Added since version 1.1.3.

Set HTTP Response Status

HTTP::status(404); // not found!

Set HTTP Header

HTTP::header('Pragma', 'no-cache');
HTTP::header('Pragma: no-cache');
HTTP::header(array(
    'Cache-Control' => 'no-store, no-cache, must-revalidate, max-age=0',
    'Cache-Control' => 'post-check=0, pre-check=0',
    'Pragma' => 'no-cache'
));

Set Cargo MIME Type

HTTP::mime('text/plain');
HTTP::mime('text/plain', 'UTF-8');

Create POST Request without HTML Form

Added since version 1.1.4.

HTTP::post('path/to' array(
    'token' => 'U2Vtb2dhIFJpZmEgc2VoYXQgc2VsYWx1Lg==',
    'user' => 'admin',
    'pass' => 'test123'
));

Get External Page Content

Added since version 1.1.4.

echo HTTP::get('path/to');

Update HTTP Query String

Added since version 1.1.6.

// ?foo=bar&baz=qux&test[foo]=bar
$results = array(
    Config::get('url_query'),
    HTTP::query('baz', 0),
    HTTP::query(array('foo' => 1, 'baz' => 2)),
    HTTP::query(array('foo' => false, 'baz' => 'false')),
    HTTP::query(array('foo' => true, 'baz' => 'true')),
    HTTP::query(array('foo' => "", 'baz' => "")),
    HTTP::query('aaa', 'bbb'),
    HTTP::query(array('test' => array('foo' => 1)))
);

Results for $results:

array(
    '?foo=bar&baz=qux&test[foo]=bar',
    '?foo=bar&baz=0&test[foo]=bar',
    '?foo=1&baz=2&test[foo]=bar',
    '?baz=false&test[foo]=bar',
    '?foo&baz=true&test[foo]=bar',
    '?foo=&baz=&test[foo]=bar',
    '?foo=bar&baz=qux&aaa=bbb&test[foo]=bar',
    '?foo=bar&baz=qux&test[foo]=1'
);
Donation and Email Subscription