php CURLOPT_FOLLOWLOCATION

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10103571/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 21:23:13  来源:igfitidea点击:

CURLOPT_FOLLOWLOCATION

php

提问by joe

I looked up google for more information. But the more I read, the more I am confused or wonder

我查了谷歌以获取更多信息。但我读得越多,我就越困惑或疑惑

I understand that CURLOPT_FOLLOWLOCATION()follows "the location", but what is the location? Is it the url that is initialized?

我知道CURLOPT_FOLLOWLOCATION()紧跟在“位置”之后,但是位置是什么?是初始化的url吗?

  curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, false); 

I only need to post data into icontact mailing list - so would this snippet above prevent the data from going in the mailing list?

我只需要将数据发布到 icontact 邮件列表中 - 那么上面的这个片段会阻止数据进入邮件列表吗?

I printed $resultand see that the data went in the correct mailing list although I cannot see whether the data are the correct ones which are from form.

我打印$result并看到数据进入了正确的邮件列表,尽管我看不到数据是否来自表单的正确数据。

回答by álvaro González

Quoting from docs:

引用文档

CURLOPT_FOLLOWLOCATIONTRUEto follow any "Location: " header that the server sends as part of the HTTP header (note this is recursive, PHP will follow as many "Location: " headers that it is sent, unless CURLOPT_MAXREDIRSis set).

CURLOPT_FOLLOWLOCATIONTRUE跟随服务器作为 HTTP 标头一部分发送的任何“Location:”标头(注意这是递归的,PHP 将跟随它发送的尽可能多的“Location:”标头,除非 CURLOPT_MAXREDIRS设置)。

When you request a URL, you can sometimes be redirected to some other URL. In PHP it'd be done with:

当您请求一个 URL 时,您有时会被重定向到某个其他 URL。在 PHP 中,它可以通过以下方式完成:

header('Location: http://example.com/');

This directive instructs CURL to load that URL instead of the original one, as HTTP mandates. There's normally no good reason to disable it.

该指令指示 CURL 加载该 URL 而不是原始 URL,正如 HTTP 要求的那样。通常没有充分的理由禁用它。

回答by Not_a_Golfer

It tells CURL to ignore 30x HTTP redirect headers or not. If set to true, "Location: <someurl>"HTTP headers in the response will cause CURL to issue another request to the location specified in this header.

它告诉 CURL 是否忽略 30x HTTP 重定向标头。如果设置为 true,"Location: <someurl>"响应中的 HTTP 标头将导致 CURL 向此标头中指定的位置发出另一个请求。