php get_headers() 函数 - 有没有办法告诉这个函数不遵循重定向?

标签 php

php get_headers() 函数 - 有什么方法可以告诉这个函数不遵循重定向吗?

$headers = get_headers("http://example.com/test", 1);
var_dump($headers);

回复:

https://i.imgur.com/zjv2G8F.png

最佳答案

您需要将 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);

Reference :

follow_location int

Follow Location header redirects. Set to 0 to disable.

Defaults to 1.

max_redirects int

The 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/

相关文章:

php - 我需要可以下载 php、html、css 教程的地方

php - Eloquent 嵌套 whereHas

php - 功能有效,但无法 +1

php - PHP/MySQL 中的竞争条件问题

php - 什么是已弃用的 LDAP_sort() 方法的替代品?

php - 在 php 5.5.1/apache 2.4.6 中忽略带下划线的 header 名称

php mysql where 语句 with AND 返回 true 即使第二个条件为 false

php - 无效或未初始化的 Zip 对象

php - PHP filter_var FILTER_VALIDATE_DOMAIN期望参数2长

php - 设置实体子实体而不从存储库加载