4.3.3
Начиная с PHP 4.3.3 вы также можете использовать эти функции с модулем NSAPI в серверах Netscape/iPlanet/SunONE.
Примеры
Пример #1 Пример использования apache_response_headers()
� езультатом выполнения данного примера будет что-то подобное:
Смотрите также
apache_request_headers() — Получает список всех заголовков HTTP-запроса
headers_sent() — Проверяет были ли и куда отправлены заголовки
headers_list() — Возвращает список переданных (или готовых к передаче) заголовков
Russian (P������) translation by Yuri Yuriev (you can also view the original English article)
��������� �� ������������� ��� ���, �� ������ ��� ������� � ���������. �� ������ ������ � �������� ������ �������� ������������ �����, ��� ���������� � �https: //�. ���� ��� ������ ������ Hello World �������� HTTP-header ��� ������ ���������. � ���� ������ �� ���������� ������ �� ������� HTTP-���������� � � ���, ��� �� ����� ������������ � ����� ���-�����������.
HTTP ������ «Hypertext Transfer Protocol» (�������� �������� �����������). ��������� ������� ���������� ���� ��������. �� ��� ������ � ������ 1990-� �����. ����� ��, ��� �� ������ � ����� ��������, ��������� �� ��� ��������� ����� HTTP. ��������, ����� �� ������� �������� ���� ������, ��� ������� �������� ����� 40 HTTP-�������� � ������� HTTP-������ ��� ������� �� ���.
��������� HTTP �������� �������� ������ ���� HTTP-�������� � �������, � ��� ����� ���������� � �������� �������, ����������� ��������, ������� � ������ ������.
������
����� �� ������� URL-����� � �������� ������, ��� ������� ���������� HTTP-������, � �� ����� ��������� ���:
������ ������ — ��� «Request Line», ������� �������� ��������� ������� ���������� �� �������. ��������� — HTTP ���������.
����� ����� ������� ��� ������� �������� ����� HTTP, ������� ����� ��������� ���:
������ ������ — ��� ������� ����������, �� ������� ������� �HTTP-���������, �� ������ ������. ����� ����� ���������� ����������� (� ������ ������ — HTML �����).
����� �� �������� �� �������� ��� ���-�������� � ���� ��������, �� ������ ������ ����� HTML, � �� ��������� HTTP, ���� ��� ���������� ���� �������� ������.
��� HTTP-������� ����� ������������ � ����������� ��� ������ �����, ����� ��� �����������, CSS-�����, ����� JavaScript � �. �. ������ ������� � ������ �����, ��� ��� ������� �������� �� ����� 40 ��� ����� HTTP-��������, ��������� �� ��������� ������ ��� �������� ������.
������ ������� ���������� ��������� ����� ��������.
VIDEO
��� ������� HTTP-���������� � ��������� ��������� ���������� Firefox:
getallheaders() �������� ������� headers. �� ������ ������������ ������ $_SERVER.
headers_list() �������� ������ headers.
����� � ���� ������ �� ������ ������� ���� � PHP.
��������� ������� HTTP
������ ������ HTTP-������� ���������� ������ ������� � ������� �� ��� ������:
«method» ���������, ����� ��� ������. �������� ��������������� ������ GET, POST � HEAD.
«path» , ��� �������, �������� ������ URL-������, ������� ��� ����� host (������). ��������, ���� ������ «https://net.tutsplus.com/tutorials/other/top-20-mysql-best-practices/» , ����� path ����� «/tutorials/other/top-20-mysql-best-practices/».
����� «protocol» �������� «HTTP» � ������, ������� ������ 1.1 � ����������� ���������.
��������� ����� ������� �������� HTTP headers ��� ���� «Name: Value» � ������ ������. ��� �������� ��������� ���������� � HTTP-������� � ����� ��������. ��������, ������ «User-Agent» ������������� ���������� � ������ �������� � ������������ �������, ������� �� �����������. «Accept-Encoding» �������� �������, ����� �� ��� ������� ��������� ������ output, �������� gzip.
��������, �� ��������, ��� ������ cookie ����� ���������� ������ HTTP-���������. � ���� �� ��������� url, ��� ���� �� � header ����.
����������� ���� ���������� �������� ���������������. ���� HTTP-������ ��� ���� ����� �� ���������:
� �� �� ����� �������� ���������� ����� �� ���-�������.
������ �������
��� �������� ����� ������������ ������ �������: GET, POST � HEAD. ��, ��������, ��� ������� � ������� �����, ������� � ��������� html-����.
GET: ��������� ���������
��� �������� �����, ������������ ��� ���������� html, �����������, JavaScript, CSS � �. �. � �������������� ����� ������ ��������� ����������� ������, ����������� � ��� �������.
��������, ��� �������� ������ Nettuts +, ����� ������ ������ HTTP-������� �������� ���:
��� ������ html ����������, ������� ������ ���������� GET-������ �����������, ������� ����� ��������� ���:
���-����� ����� ��������� ��� ����� GET. ��� ������.
����� ��� ����� ����������, HTTP-������ ���������� ���:
�� ������ ������, ��� ������ ���� ����� ��� �������� � ������ �������.
POST: �������� ������ �� ������
���� ���� �� ������ ���������� ������ �� ������ � ������� GET � ������ �������, �� ������ ������� POST ����� ����������������. �������� ������� ������� ������ � ������� GET ��������������� � ����� �����������.
������� POST ���� ����� ������������ ���-�������. ������� ������� ���������� ������ ����� �� ����� POST.
�������� ���� ����� ������� HTTP-������ ��������� �������:
����� ����� �������� ��� ������ �������:
���� � ������ ������ ������ /foo.php, � ������ ��� ������ �������.
��������� ��������� Content-Type � Content-Length, ������� ������������� ���������� �� ������������ ������.
��� ������ ������ ������������ ����� ����������, � ��� �� �������, ��� � ������ �������.
������� POST ������ ����� ����� ���� ������� ����� AJAX, ����������, cURL � �. �. � ��� ����� �������� ������ ���������� ��� ������������� ������ POST.
HEAD: ��������� ���������� ���������
VIDEO
HEAD ��������� GET, �� ����������� ����, ��� ������ �� ���������� ���������� HTTP-������. ����� �� ����������� ������ HEAD, ��� ��������, ��� ��� ���������� ������ ��� ������ � HTTP headers, � �� ��� ��������.
������ �� ����������� ������ HEAD, ��� ��������, ��� ��� ���������� ������ ��� ������ � HTTP headers, � �� ��� ��������.
� ������� ����� ������ ������� ����� ���������, ��� �� �������� ������ ��� ����� caching. �� ����� ����� ���������, ���������� �� �������� ������.
��������, ���� � ��� ����� ������ �� ���-�����, �� ������ ������������ ���������� HEAD-������� ������ �� ���, ����� ��������� ������� ������������ ������. ��� ����� ������� �������, ��� ��� ������������� GET.
��������� ������ HTTP
����� ����, ��� ������� ���������� HTTP-������, ������ �������� HTTP-�������. �������� �������, �� �������� ���:
������ ������� ������ �������� ��������. ������ ��� ����� HTTP/1.x ��� HTTP/1.1 �� ����������� ��������.
��������� ����� — ��� ��� ���������, �� ������� ������� �������� ���������. ��� 200 ��������, ��� ��� ������ GET ��� �������� � ������ ����� ���������� ������������ ��������� ����� ����� headers.
�� ��� ������ «404» pages. ��� ����� ���������� �������� �� ����� ���� ��������� HTTP-������. ���� ������ GET ����� ������ ��� path, ������� ������ �� ����� �����, �� ������� �� 404, � �� 200.
��������� ����� ������ �������� headers ��� ��, ��� HTTP-������. ��� �������� ����� ��������� ���������� � ����� ������� ��� ��������� ��������� ��������/�����, ���� mime � ������.
����� ��, ����������� ���� headers �� ����� ���� �������� ���������������.
���� ������� HTTP
200 ������������ ��� �������� ��������.
300 ��� ���������������.
400 ������������, ���� �������� �������� � ��������.
500 ������������, ���� �������� �������� � ��������.
200 OK
��� ����������� �����, ���� ��� ��������� ������������ � ����� �� �������� ������.
206 Partial Content
���� ���������� ����������� ������ �������� ������������ �����, ������������ ��� 206.
��� ����� ������������ � ����������� �������, ������� ����� ���������� � ����������� �������� ��� ��������� �������� �� �����.
404 Not Found
����� ������������� �������� ��� ���� �� �������, ������ ���������� ��� ������ 404.
401 Unauthorized
���������� ������� ���-�������� ���������� ���� ���. ���� �� �� ����� ����� ���������, �� ������ ������� ��������� � ����� ��������.
�������� ��������, ��� ��� ��������� ������ � ���������, ���������� ������� HTTP, ������� �������� ������� ��� ����� ��������� �������:
403 Forbidden
���� ��� �� �������� ������ � ��������, ���� ��� ����� ���� ��������� � ��� �������. ��� ����� ����������, ����� �� ��������� ������� URL-����� ��� �����, � ������� ��� ��������� ��������. ���� ��������� ������� �� ��������� ���������� ���������� �����, �� �������� ������ 403.
VIDEO
��������, �� ���� ��������� ������� � ������ ����� �����������. ������ ���� ����� � ������� ���� .htaccess � ���� �������: «Options -Indexes» . ������, ����� � ������� ������� http://localhost/images/ — � ���� ���:
���������� ������ ������� ���������� ������� � 403 ����� ���� ����������. ��������, �� ������ ����������� �� IP-������ � ������� ��������� �������� htaccess.
302 (or 307) Moved Temporarily & 301 Moved Permanently
��� ��� ���� ������������ ��� ��������������� ��������. ��������, ����� �� ����������� ������ ���������� URL, ����� ��� bit.ly, ������ ��� ��� �������������� �����, ������� ���� �� ������.
302 � 301 �������������� ��������� ����� ������, �� ��� ����� ����� ��������� �������� ��� spiders ��������� ������. ��������, ���� ��� ���� �� ����� ��� ������������, �� ������ ������������� ��� � ������ ����� � ������� 302. ��������� ������� ��������� �������� ����� �������� � �������. �� ���� �� ������������� � �������������� 301, ��� ������� spider, ��� ��� ���� �������� � ��� ����� ��������. �� ����� ������ �����������: http://www.nettuts.com ��������� �� https://net.tutsplus.com/ ��������� 301 ��� ������ 302.
500 Internal Server Error
���� ��� ������ ������������ ��� ���� ���-�������. ����������� �������� CGI �� ������� ������ ��������������� � �������, � ������� �� PHP. ���� ���� ��������� ������, ��� ������ �������� ��� ������� 500. � ����� ����������� ������ ������ � �������� ������ �������, ����� ����� ��������� �� �������.
Complete List
�� ������ ����� ������ ������ ����� ��������� HTTP � �� ����������� here.
��������� HTTP � �������� HTTP
������ �� ���������� ��������� �� �������� ���������������� HTTP headers , ��������� � HTTP requests.
����� ��� ��� ��������� ����� ����� � ������� $ _SERVER � PHP. �� ����� ������ ������������ ������� getallheaders() ��� ���������� ���� ���������� ������������.
HTTP-������ ������������ �� ������������ IP-������. �� ��� ��� ����������� �������� �������� ��������� ��������� ������ ��� ����� IP, ��� ������ �����, ����� �������� ��� ���� �������.
��� � �������� ��� host, ������� ����� � ��������.
� PHP ��� ����� �����, ��� $_SERVER[‘HTTP_HOST’] ��� $_SERVER[‘SERVER_NAME’].
User-Agent
���� ��������� ����� ��������� ��������� ������ ����������, ����� ���:
��� � ������ ��������.
�������� � ������ ������������ �������.
���� �� ���������.
������ ��� ���-����� ����� �������� ����������� ����� ���������� � ����� �������� surfers. ��������, ��� ����� ����������, ���������� �� surfer ��������� ������� � �������������� �� �� ��������� ������ ������ ���-�����, ������� ����� �������� � ������ �����������.
� PHP ����� ���� ������� ���: $_SERVER[‘HTTP_USER_AGENT’].
Accept-Language
���� ��������� ���������� ��������� ����� �� ���������. ���� ���� ����� ������ �������� ������, �� ����� ������������� ������ surfer �� ������ ���� ������.
�� ����� ��������� ��������� ������, ���������� ��������. ������ — ��� ���������������� ����, � ������ �� ������������� ������ ����� ����� �������� �q�, ������� ������������ ����� ������ ������������ ������������ ��� ����� (min. 0 max. 1).
� PHP ��� ����� ����� ���: $ _SERVER [«HTTP_ACCEPT_LANGUAGE»].
Accept-Encoding
����������� ����������� ��������� ������������ gzip � ���������� ��� � header. ����� ���-������ ����� ��������� �������� HTML-��� � ������ �������. ��� ��������� ��������� ������ �� 80% ��� �������� ���������� ����������� � �������.
� PHP ��� ����� ����� ���: $ _SERVER [«HTTP_ACCEPT_ENCODING»]. ������, ����� �� ����������� ������� ��������� ������ ob_gzhandler(), ��� ����� ��������� �������� �������������, ������� ��� ��� �� �����.
If-Modified-Since
���� ���-�������� ��� �������� � ���� � �������� � �� ��������� ��� �����, ��� ������� ����� ���������, ��� �� �������� �������, �������� ���������:
VIDEO
���� �� �� ��������� � ���� ����, ������ ���������� ��� ������ �304 Not Modified�, � ���������� — ���, � ������� ��������� ���������� �� cache.
� PHP ��� ����� ����� ���: $ _SERVER [‘HTTP_IF_MODIFIED_SINCE’].
���������� ����� HTTP-��������� Etag, ������� ����� ������������ ��� �������� �������� ����. �� ��������� �� ���� � ��������� �����.
Cookie
��� ������� �� ��������, ��� ���������� ����� cookie, ���������� � ����� �������� ��� ����� ������.
��� ���� name=value, ���������� ������� � �������. Cookies ����� ����� ��������� id ������.
� PHP ��������� cookie-����� ����� ���� �������� � ������� ������� $ _COOKIE. �� ������ �������� ���������� � ���������� ������, ��������� ������ $ _SESSION, � ���� ��� ����� id ������, �� ������ ������������ ������� session_id () ������ cookie.
Referer
��� ������� �� ��������, ���� HTTP header �������� ��������� url.
��������, ���� � ����� �� �������� �������� Nettuts + � ����� ������ �� ������, ���� header ����� ��������� � ��� �������:
� PHP ��� ����� ����� ��� $ _SERVER [‘HTTP_REFERER’].
��������, �� ��������, ��� ����� �referrer� �������� � �������, ��� �referer�. � ���������, �� ����������� � ����������� ������������ HTTP �������� ������� � �������.
Authorization
����� ���-�������� ����������� �����������, ������� ��������� ���� ����� � �������. ����� �� ������� ��� ������������ � ������ � ���� ����, ������� ���������� ������ HTTP-������, �� �� ���� ��� �� �������� ���� header
������ ������ header ����� ��������� base64. ��������, base64_decode (‘bXl1c2VyOm15cGFzcw ==’) ��������� ‘myuser: mypass’
� PHP ��� �������� ����� ����� ��� $ _SERVER [‘PHP_AUTH_USER’] � $ _SERVER [‘PHP_AUTH_PW’].
��������� �� ���� �����, ����� �� ��������� � ��������� WWW-Authenticate.
��������� HTTP � ������� HTTP
������ �� ���������� ��������� �� �������� ���������������� HTTP headers, ��������� � HTTP-�������.
� PHP �� ������ ���������� ��������� ������, ��������� ������� header(). PHP ��� ���������� ����������� ��������� �������������, ��� �������� ����������� � ��������� ������ cookie � ������. �� ������ ������� headers, ������� ������������ ��� ����� ������������ � ������� ������� headers_list (). �� ������ ���������, ���� �� ��� ���������� ��������� � ������� ������� headers_sent().
Cache-Control
����������� �� w3.org: ����� ��������� Cache-Control ������������ ��� �������� ��������, ������� ������ ����������� ����� ����������� ����������� �� ������� ��������/�������. ��� ���������� ������������ �������� ����� � ������, ������� ����� ������������ ��� ��������-���������.
«public» ��������, ��� ����� ����� ���� ��������� ��� ������. «max-age» ���������, ������� ������ ������������ ���. ���������� ����������� ������ ����� ����� ������� �������� �� ������ � ���������� �����������, � ����� ��������� ����� �������� � ��������.
����������� ����� ����� ���� ������������� � ������� ��������� «no-cache».
����������� �������� � w3.org.
Content-Type
���� header ��������� «mime-type» ���������. ����� ������� ����������, ��� ���������������� ���������� �� ��������� �����. ��������, �������� html (��� PHP-������ � ������� html) ����� ���������� ���:
«text» — ��� ���, � «html» — ������ ���������. ��������� ����� ����� ��������� ������ ����������, ����� ��� charset.
��� gif-����������� ��� ����� ���� ����������.
������� ����� ������������ ������� ���������� ��� ���������� �������� �� ������ mime-type. ��������, ��� �������� � �������� Adobe Reader:
VIDEO
��� �������� �������� Apache ������ ����� ���������� mime-��� ��������� � ��������� ��������������� header. ����� ����, ����������� ��������� ����� ��������� ������� ������������������ � ��������������� ����� mime, ���� ��������� ������� ������� ��� �����������.
�� ������ ����� ������ ����� ����� mime here.
� PHP �� ������ ������������ ������� finfo_file() ��� ����������� mime-���� �����.
Content-Disposition
���� header ��������� �������� ������� ���� �������� �����, ������ ����, ����� �������� ���������������� ����������. ������:
��� �������� ������� ������� ���:
�������� ��������, ��� ��������������� ��������� Content-Type ����� ������ ���� ��������� ������ � ����:
Content-Length
����� ������� ����� ������������ ��������, ������ ����� ������� ��� ������ (� ������), ��������� ���� header.
��� �������� ������� ��� �������� ������. ������ ��� ������� ����� ���������� ��� ��������.
��������, ��� ��������-�����, ������� � �������, ��������� ��������� ��������.
������ � ��������� ���������������� ��������� Content-Length
������ ��������� �����:
������� ����� ������ �������, ������� ������ ���� ���������, �� �� �� ����� ����� �����. � ��������� ���������� �� ���������� ��������.
��� ��� ���� header, ������� ������������ ��� �����������. ��� �������� ���:
���-������ ����� ���������� ���� header � ������ ����������, ������� �� �����������. �������� ����� ���� �������� �� ��������� ��������� ����, ������� ����� ��� ���� ����������� ����� �����. ������� ����� ��������� ��� ��������, ��� ��� �� �������� ��������. � ��������� ���, ����� ������� ����������� ��� �� ����, �� ���������� ��� � HTTP-�������:
���� �������� Etag ��������� ��������� � ����, ������ ����� ���������� ��� 304 ������ 200, � �������� �����������. ������� ����� ��������� ���������� �� ������ ����.
Last-Modified
��� ������� �� ��������, ���� header ��������� ���� ���������� ��������� ��������� � ������� GMT:
��� ���������� �������� ������ ������ ��� cache ���������. ������� ����� ��������� ��� � HTTP-�������:
�� ��� �������� �� ���� ����� � ������� «If-Modified-Since».
Location
���� ��������� ������������ ��� ���������������. ���� ��� ������ 301 ��� 302, ������ ����� ������ ��������� ���� header. ��������, ����� �� ��������� �� �������� http://www.nettuts.com, ��� ������� ������� ���������:
� PHP �� ������ ������������� surfer ���:
�� ���������, ��� �������� 302 ��� ������. ���� �� ������ ������ 301 ���������:
Set-Cookie
����� ���-���� ����� ���������� ��� �������� ���� cookie � ����� ��������, �� ����� ������������ ���� header.
������ ���� cookie ������������ ��� ��������� header. �������� ��������, ��� ����� cookie, ������������� � ������� JavaScript, �� �������� ����� HTTP headers.
� PHP �� ������ ���������� cookie-�����, ��������� ������� setcookie(), � PHP ���������� ��������������� HTTP headers.
��� �������� � �������� ����� ���������:
VIDEO
���� ���� ��������� ����� �������� �� �������, cookie ���������, ����� ���� �������� �������.
WWW-Authenticate
���� ����� ��������� ���� header ��� �������������� ������������ ����� HTTP. ����� ������� ������ ���� header, �� ������� ���������� ���� ����� � �������.
��� ����� ��������� ���:
� ����������� PHP ���� section, � ������� ��������� ������� ����, ��� ��� ������� � PHP.
Content-Encoding
���� header ������ ���������������, ����� ������������ ���������� ���������.
� PHP, ���� �� ����������� ������� ��������� ������ ob_gzhandler(), ��� ����� ������������� �����������.
����������
������� �� ���������. �������, ��� ������ �������� ������� ��������� ������ ��� �������� HTTP Headers. ����������, �������� ���� ����������� � ������� ����, � � ���������� ���� ��� ����� ������ �������.
I am trying to get an image to cache on a website. The image is served by PHP in which I am setting a response header of cache control with the appropriate value, however this is not caching the image, I think it might have something to do with the request header having a cache control of no-cache? Headers below:
How do I get these images to cache?
1 Answer 1
Your idea about the lack of caching happening because of the Cache-Control: no-cache request header is correct; that request header tells any possible caches along the way to not use any cached data for the requested resource (see the «End-to-end reload» section of RFC 2616).
To be specific, your response may actually be being cached. But that Cache-Control: no-cache header in the request says that that particular HTTP client does not want to take advantage of the cache; another HTTP client may be able to use the cached resource.
FPublisher
Web-����������: ���� ������
������������ PHP
(PHP 4 >= 4.3.0, PHP 5)
apache_response_headers � �������� ������ ���� ���������� HTTP ������
��������
array apache_response_headers ( void )
���������� ������, ���������� ��� ��������� ������ Apache. ��� ������� �������� ������ ��� ������ PHP >= 4.3.0.
��������� �����������:
���������� �� �����
��������� 14 ����� 2020 ����
�p���� Genesis (�� ��p��p������� ��p������)
��������� �� ������ � Vim
��������� 05 ������� 2020 ����
Vim �������� ������ ��������, �� ������ � ��� �� ������ ��������. �������� ���� ����� ��������������� �����-�� ���� �������� ��� ������ crontab, ��� ������ ��������� ������ � viv �����.
������: Error: Cannot find a val >��������� 13 �������� 2020 ����
���� ��������� ������ �� centos 5 ���� YumRepo Error: All mirror URLs are not using ftp, http[s] or file. Eg. Invalid release/
Linux Optimization
��������� 30 ���� 2012 ����
Понравилась статья? Поделиться с друзьями: