What is header in PHP
The header in php is mainly used to send the original http header to the client. It is commonly used to notify the browser that the page does not exist, delay redirection, indicate content type, declare downloaded files, and update the current document. Disable caching, display a login dialog requiring verification, etc.
[Recommended course:PHP Tutorial】
The header() function in PHP is used to send the original HTTP header to the client. Today I will share with you some commonly used header function headers in PHP. It has certain reference value and I hope it will be helpful to everyone.
header('HTTP/1.1 200 OK'); // ok normal access
header('HTTP/1.1 404 Not Found'); //notify the browser that the page does not exist
header('HTTP/1.1 301 Moved Permanently'); //Set the address to be permanently redirected 301
header('Location: http://www.ithhc.cn/'); //Jump to a new address
header('Refresh: 10; url=http://www.ithhc.cn/'); //Delayed redirection means jumping every few seconds
header('X-Powered-By: PHP/6.0.0'); //Modify X-Powered-By information
header('Content-language: en'); //Documentation Language
header('Content-Length: 1234'); //Set the content length
header('Last-Modified: '.gmdate('D, d M Y H:i:s' , $time).' GMT'); //Tell the browser the last modification time
header('HTTP/1.1 304 Not Modified'); //Tell the browser that the document content has not changed
Indicates the content type
header('Content-Type: text/html; charset=utf-8'); //Web page encoding
header(' Content-Type: text/plain'); //Plain text format
header('Content-Type: image/jpeg'); //JPG, JPEG
header('Content- Type: application/zip'); // ZIP file
header('Content-Type: application/pdf'); // PDF file
header('Content-Type: audio/ mpeg'); //Audio file
header('Content-type: text/css'); //css file
header('Content-type: text/javascript'); //js file
header('Content-type: application/json'); //json
header('Content-type: application/pdf'); //pdf
header('Content-type: text/xml'); //xml
header('Content-Type: application/x-shockw**e-flash'); //Flash animation
Declare a downloaded file
header('Content-Type: application/octet-stream');
header(' Content-Disposition: attachment; filename="ITblog.zip"');
header('Content-Transfer-Encoding: binary');
readfile('test.zip');
Disable caching for the current document
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
Display a login dialog box that requires verification
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Top Secret"');
Declare an xls that needs to be downloaded File
header('Content-Disposition: attachment; filename=ithhc.xlsx');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml. sheet');
header('Content-Length: '.filesize('./test.xls'));
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Pragma: public');
readfile('./test.xls') ;
The above is the detailed content of What is header in PHP. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

[SpringBoot] Passing parameters in the Header through Feign calls How to pass Header parameters through Feign Problem description When we use Feign to request the Api interface of another service in Spring Cloud, there is a need to pass the parameters in the Header. If no special processing is done, it will The parameters in the Header will be lost. Solution 1: Pass it through @RequestHeader(name="headerName"). For example: Feign is defined as follows @FeignClient(name="service-name")pub

The Linux header refers to the beginning of a file or data stream, which is used to contain metadata about the content. By correctly writing and using Header files, developers can better utilize system resources and improve code readability and Maintainability.

How to implement jump in php header: 1. Use "Header("Location:$url");" syntax to implement jump; 2. Use if judgment to implement jump, with jump statements such as "if($_COOKIE[" u_type"]){ header('location:register.php'); } else{ setcookie('u_type','1','86400*360');".

PHP is a powerful programming language that can be used to create dynamic websites and web applications. One of the most powerful features is PHP’s header() method. In this article, we will explore how to use PHP’s header() method to adjust web pages.

Differences: 1. The head tag is used to define the head of the document, which is a container for all head elements, and the header tag is used to define the header (introduction information) of the document; 2. All browsers support the head tag, and older versions of browsers None of the browsers support the header tag, and browsers such as IE9+ and above are required to support the header tag.

Complete list of PHP file download functions: File download example analysis of readfile, header, Content-Disposition and other functions. File download is one of the essential functions in Web applications, and PHP, as a widely used Web development language, provides many A function and method to implement file downloading. This article will introduce commonly used file download functions in PHP, including readfile, header, Content-Dispo

Nginx can distribute requests to different servers based on custom identifiers in the request headers. Specifically, you can use the map directive to map the custom identifier in the request header to a different backend server address, and then use the proxy_pass directive to forward the request to the corresponding backend server. The following is an example configuration file: http{map$http_my_header$backend{defaultbackend1.example.com;value1backend2.example.com;value2backend3.example.com;}upstreambackend1{serv

By modifying the nginx conf file, you can easily customize the HTTPHeader. Nginx uses the ngx_headers_more module to add and delete outbound and inbound Header information. By default, this module is not added to the source code of Nginx. If you want to use related functions, you need to add this module when compiling Nginx. The Nginx in my server did not add this module when compiling. Use -V to view the current Nginx compilation parameters: [root@z-dig~]#nginx-Vnginxversion:www.z-dig.combuiltbygcc4.4.720120313(RedHat4
