php CURLOPT_RETURNTRANSFER 设置为 true 在托管服务器上不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12269929/
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
CURLOPT_RETURNTRANSFER set to true doesnt work on hosting server
提问by Marcel Gent Simonis
I'm trying to process result from $data = curl_exec($ch);instead of printing it on the screen. In order to achieve that I set the option CURLOPT_RETURNTRANSFERto truelike this:
我正在尝试处理结果$data = curl_exec($ch);而不是将其打印在屏幕上。为了达到我设定的选项CURLOPT_RETURNTRANSFER,以true这样的:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
On my local server this works as expected but when I put the same file online on my server it doesn't work.
在我的本地服务器上,这按预期工作,但是当我将相同的文件放在我的服务器上时,它不起作用。
When I set CURLOPT_RETURNTRANSFERto falseit works.
当我设置CURLOPT_RETURNTRANSFER到false它的工作原理。
What am I doing wrong?
我究竟做错了什么?
回答by Anthony Hatzopoulos
If you set CURLOPT_RETURNTRANSFERto trueor 1then the return value from curl_execwill be the actual result from the successful operation. In other words it will not return TRUEon success. Although it will return FALSEon failure.
如果设置CURLOPT_RETURNTRANSFER为true或 ,1则返回值curl_exec将是成功操作的实际结果。换句话说,它不会TRUE成功返回。虽然它会FALSE在失败时返回。
As described in the Return Values section of curl-execPHP manual page: http://php.net/manual/function.curl-exec.php
如curl-execPHP 手册页的返回值部分所述:http: //php.net/manual/function.curl-exec.php
You should enable the CURLOPT_FOLLOWLOCATIONoption for redirects but this would be a problem if your server is in safe_modeand/or open_basediris in effect which can cause issues with curl as well.
您应该启用CURLOPT_FOLLOWLOCATION重定向选项,但如果您的服务器已启动safe_mode和/或open_basedir正在运行,这将是一个问题,这也会导致 curl 出现问题。
回答by rayalois22
If it works fine on your local environment, probably your remote server's IP is being blocked by the server at the target URL you've set for cURL to use. You need to verify that your remote server is allowed to access the URL you've set for CURLOPT_URL.
如果它在您的本地环境中运行良好,则可能是您的远程服务器的 IP 被您为 cURL 设置的目标 URL 的服务器阻止了。您需要验证您的远程服务器是否可以访问您为CURLOPT_URL设置的 URL。
回答by Ran Da
Just try this line:
试试这一行:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
after:
后:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

