通过PHP cURL获取文件内容

And*_*rei 16 php curl

我有一个网站.我们称之为http://www.domain.com.现在,在这个domain.com上我想显示文件内容http://www.adserversite.com/ads.php.我怎样才能用cURL或其他方法做到这一点?我不想用iframe.

谢谢

m4t*_*1t0 47

您可以file_get_contents像Petr说的那样使用,但是您需要allow_url_fopen在您php.ini的主机中激活,也许您的主机不允许您更改此设置.

如果您更喜欢使用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);
Run Code Online (Sandbox Code Playgroud)

  • 你是对的,file_get_contents是可取的,但我在过去遇到过共享主机的问题. (2认同)

Pet*_*etr 12

echo file_get_contents('http://www.adserversite.com/ads.php');
Run Code Online (Sandbox Code Playgroud)

谁需要卷曲这个简单的任务?

  • 注意:如果`allow_url_fopen`在php.ini中为"On",这在某些共享主机上可能不正确,例如@ m4t1t0已经提到过.我个人在安装curl时遇到过几次情况,但是`allow_url_fopen`被禁用了. (15认同)