通过 PHP cURL 获取文件内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12781876/
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
Get file content via PHP cURL
提问by Andrei
I have an website. Let's call it http://www.domain.com. Now, on this domain.com I want to display the file contents of http://www.adserversite.com/ads.php. How can I do that with cURL or another method? I don't want to use iframe.
我有一个网站。让我们称之为http://www.domain.com。现在,在这个 domain.com 上,我想显示http://www.adserversite.com/ads.php. 我怎样才能用 cURL 或其他方法做到这一点?我不想使用iframe.
Thanks
谢谢
采纳答案by Petr
echo file_get_contents('http://www.adserversite.com/ads.php');
Who needs curl for this simple task?
谁需要 curl 来完成这个简单的任务?
回答by m4t1t0
You can use file_get_contentsas Petr says, but you need to activate allow_url_fopenin your php.iniand perhaps your hosting do not allow you to change this.
您可以file_get_contents像 Petr 所说的那样使用,但您需要allow_url_fopen在您php.ini的主机中激活,而且您的主机可能不允许您更改此设置。
If you prefer to use CURL instead of file_get_contents, try this code:
如果您更喜欢使用 CURL 而不是file_get_contents,请尝试以下代码:
<?php
$url = 'http://www.adserversite.com/ads.php';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$data = curl_exec($curl);
curl_close($curl);

