我有一个网站,假设它叫做 http://www.domain.com
。现在,在这个 domain.com 上,我想显示来自http://www.adserversite.com/ads.php
的文件内容。我该如何使用cURL或其他方法实现?我不想使用 iframe
。
谢谢
file_get_contents
,但你需要在php.ini
中启用allow_url_fopen
,也许你的主机不允许更改这个设置。如果你更喜欢使用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);
allow_url_fopen
默认为开启状态 ;) - Berry Langerakecho file_get_contents('http://www.adserversite.com/ads.php');
谁需要在这个简单的任务中使用curl?
allow_url_fopen
设置为"On",那么在某些共享主机上可能不是这样的,就像@m4t1t0已经提到的那样。我个人曾多次遇到curl已安装但allow_url_fopen
被禁用的情况。 - zergussino