我可以寫一個PHP文件(的index.php),當有人指出它的瀏覽器PHP代理用於獲取其他域的內容
http://www.domain.org/some?params=a&b=1
它返回的
http://www.OTHERdomain.org/some?params=a&b=1
內容我應該用culr嗎?
我可以寫一個PHP文件(的index.php),當有人指出它的瀏覽器PHP代理用於獲取其他域的內容
http://www.domain.org/some?params=a&b=1
它返回的
http://www.OTHERdomain.org/some?params=a&b=1
內容我應該用culr嗎?
您可以創建一個名爲proxy.php
的頁面,或者類似將URL作爲參數的頁面。然後,您可以用URL中的otherdomain.org
代替domain.org
。然後使用CURL獲取內容並將其返回。
從http://www.php.net/manual/en/curl.examples-basic.php#88055,這是你需要的代碼:
<?php
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "example.com");
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
?>
我在關閉前添加了echo $輸出。 – 2010-09-03 23:58:16
你可以使用的file_get_contents(URL)如果你有允許去URL的fopen設置爲「真」在php.ini文件 – Andreas 2010-09-03 23:47:51
又有什麼url的值? – 2010-09-03 23:52:41