


header location php header Detailed instructions and experience on page 1/2
No matter how many headers the page has, it will execute the last one, but it is conditional, for example:
header('Location:http://www.jb51.net');
header('Location:http://www. g.cn');
header('Location:http://www.baidu.com');
This will jump to Baidu
header('Location:http://www.jb51.net'); echo 'This site';
header('Location:http://www.g.cn');
header('Location:http://www.baidu.com');
This will jump to google
It is a detailed instruction on the use of the header function
1. Function:
~~~~~~~~~
PHP just sends the header of the HTML document to the browser using the HTTP protocol, telling the browser how to process this page. The transmitted content needs to be familiar with the HTTP protocol, which has nothing to do with PHP. The traditional header must contain one of the following three headers and can only appear once.
Location: xxxx:yyyy/zzzz
Content-Type: xxxx/yyyy
Status: nnn xxxxxx
Second, let’s first understand how the HTTP protocol works
~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~
HTTP protocol is based on the request/response paradigm. After a client establishes a connection with the server, it sends a request to the server. The format of the request is a uniform resource identifier, a protocol version number, followed by MIME information including request modifiers, client information and possible content. After receiving the request, the server gives corresponding response information. The format is a status line including the protocol version number of the information, a success or error code, followed by MIME information including server information, entity information and possible content.
It is divided into four processes. In the HTTP protocol, the server refers to the part that provides HTTP services, and the client refers to the browser or download tool you use, etc. During communication, the client sends a request for connection, and the server establishes the connection; then, the client sends an HTTP request (Request), and the server returns response information (Respond), thus completing an HTTP operation.
3. The meaning of HTTP protocol status code
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1×× Reserved
2×× Indicates a request Successfully received
3×× To complete the request, the customer needs to further refine the request
4×× Customer error
5×× Server error
IV. Operation examples:
~~~~~~~~~~~~~
< ;1> Redirect function, the most common
Header("Location: http://www.php.net");
?>
<2> forces users to visit this page every time Get the latest data at the same time, rather than using the cache that exists on the client.
//Tell the browser the expiration time of this page (expressed in Greenwich Mean Time), as long as it is a date that has passed.
header("Expires: Mon, 26 Jul 1970 05:00:00 GMT");
//Tell the browser the last updated date of this page (expressed in Greenwich Mean Time), which is the same day, the purpose is to force the browser to obtain Latest information
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
//Tell the client browser not to use cache
header("Cache-Control: no-cache, must-revalidate");
//Parameters (compatible with previous servers), that is, compatible with HTTP1.0 protocol
header("Pragma: no-cache");
//Output MIME type
header(" Content-type: application/file");
//File length
header("Content-Length: 227685");
//Accepted range units
header("Accept-Ranges: bytes");
//Missing Time-saving file name in the file saving dialog box
header("Content-Disposition: attachment; filename=$filename");
?>
<3> Output status value to the browser, mainly used for access permission control
header('HTTP/1.1 401 Unauthorized');
header('status: 401 Unauthorized');
?>
For example, if you want to restrict a user from accessing this page, you can set the status to 404, as follows As shown, the browser will display that the page does not exist
header('HTTP/1.1 404 Not Found');
header("status: 404 Not Found");
?>
Note : The traditional header must contain one of the following three headers and can only appear once. Content-Type: xxxx/yyyy Location: xxxx:yyyy/zzzz Status: nnn xxxxxx can appear more than twice in the new multipart header specification (Multipart MIME).
Usage Example
Example 1: This example redirects the browser to the official website of PHP.
Header("Location: http://www.php.net"); exit; >?
Example 2: If you want the user to get the latest data every time, instead of the data in the Proxy or cache, you can use The following header
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT "); header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache"); >?
Example 3: Let the user's browser display the file not found Information.
header("Status: 404 Not Found"); >?
Example 4: Allow users to download files.
header("Content-type: application/x-gzip");
header("Content-Disposition: attachment; filename=filename");
header("Content-Description: PHP3 Generated Data"); >?
Current page 1/2 12Next page
The above introduces header location php header detailed usage instructions and usage experience on page 1/2, including header location content. I hope it will be helpful to friends who are interested in PHP tutorials.

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

AI Hentai Generator
Generate AI Hentai for free.

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



Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Alipay PHP...

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.
