php get_headers() 函数 - 有什么方法可以告诉这个函数不遵循重定向吗?
$headers = get_headers("http://example.com/test", 1);
var_dump($headers);
回复:
最佳答案
您需要将 max_redirects
上下文选项设置为 1 或仅禁用 follow_location
:
$context = stream_context_create(
[
'http' => [
'follow_location' => 0,
],
]
);
$headers = get_headers("http://example.com/test", true, $context);
var_dump($headers);
follow_location
intFollow Location header redirects. Set to 0 to disable.
Defaults to 1.
max_redirects
intThe max number of redirects to follow. Value 1 or less means that no redirects are followed.
Defaults to 20.
关于php get_headers() 函数 - 有没有办法告诉这个函数不遵循重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68323607/