Memory App

First, there is HTTP request from a client. Server decodes the data and send it to PHP interpreter. Finally, Server send response data to the client. You can use header() function to overwrite standar headers (must be called before any other output).

    // Most common use of headers is to redirect the user to another page
You can set php.ini in order to be able to output data even after you send body content.

    ; php.ini
    output_buffering = 4096
Compresion can make as much as 90% decrease in file size, but uses more resources than a typical request. You can enable comprension on file side.

    // first line in php file

Or you can enable compresion on server side (can be easily turned on/off).

    ; PHP.ini

    zlib.output_compression = on (off default)
    zlib.output_compression_level = 9 (-1 default)

    // this will keep the page in browser's cache for 30 days

    $date = gmdate("D, j M Y H:i:s", time() + 30*3600*24); // 30 Days from now
    header("Expires: " . $data . " UTC");
    header("Cache-Control: Public");
    header("Pragma: Public");
Authentication Required message to the client

    if (!isset($_SERVER['PHP_AUTH_USER'])) {
        header('WWW-Authenticate: Basic realm="Login"');
        header('HTTP/1.0 401 Unauthorized');
    } else {
        echo $_SERVER['PHP_AUTH_USER'];
        echo $_SERVER['PHP_AUTH_PW'];
Other header functions

    header() | Sets an HTTP header | void
    header_list() | List of header send (or to be send) | array
    header_sent() | Check if headers have been sent | boolean
    header_remove() | Removes a HTTP header (previously set with headers) | void
Send post request

    $url = '';
    $data = array('key1' => 'value1', 'key2' => 'value2');

    // use key 'http' even if you send the request to https://...
    $options = array(
        'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencodedrn",
        'method'  => 'POST',
        'content' => http_build_query($data)
    $context  = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    if ($result === FALSE) { /* Handle error */ }



Top Reference > Programming
0/0 (80)  
Not Logged