search
Homephp教程php手册php header请求重写的一个问题

同事叫我帮忙解释一个问题:一个PHP生成的重定向请求,在Nginx日志里产生两种截然不同的记录,一种响应体大小是零个字节,另一种响应体大小是五个字节.

现在年纪大了,面对问题时的嗅觉不再灵敏,第一感觉零是正确的,心想是不是重定向后忘记退出了,后面还有内容输出,可是查了一下代码发现没有问题,代码如下:

<?php 
header(&#39;Location: /path&#39;); 
exit;

在绕了一大圈之后,我猛然意识到环境是Nginx+PHP,响应没有「Content-Length」,数据是通过「Transfer-Encoding」分块发送的,所以重定向的空响应体实际类似:

0\r\n\r\n

不多不少,正好五个字节,细节大家可以参考Chunked transfer encoding,如此看来在此类空响应体的情况下,PHP主动输出一个「Content-Length:0」说不定会更好些.

那零个字节的响应如何解释呢?查询日志发现如下两种情况:

HEAD “/path HTTP/1.1″ 302 0

GET “/path HTTP/1.0″ 302 0

前者是HEAD请求,不需要响应体,后者是HTTP/1.0,不支持「Transfer-Encoding」.


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function