MemoryRefresh!

Http / Headers   Headers



Questions 1 Answers 0%

Pages   0 from 91
Questions   0 from 142

Reset


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).
<?php // Most common use of headers is to redirect the user to another page header("Location: new.com"); 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.
<?php // first line in php file ob_start("ob_gzhandler"); ?> 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) Cache
<?php // 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
<?php 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
<?php $url = 'server.com'; $data = array('key1' => 'value1', 'key2' => 'value2'); // use key 'http' even if you send the request to ... $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 */ } var_dump($result); stackoverflow.com

Related Pages

Headers
URL
Cookies
Sessions


0% 100%
 
 
0 pages 91 pages
1) What is the first step when generating HTML page?





2) What happens before the client output the HTML page?







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).
<?php // Most common use of headers is to redirect the user to another page header("Location: new.com"); 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.
<?php // first line in php file ob_start("ob_gzhandler"); ?> 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) Cache
<?php // 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
<?php 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
<?php $url = 'server.com'; $data = array('key1' => 'value1', 'key2' => 'value2'); // use key 'http' even if you send the request to ... $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 */ } var_dump($result); stackoverflow.com

References









Programming

Php
   
Regex
   
MySQL
   
Css
   
jQuery
   
Git
   


References