IT貓撲網(wǎng):您身邊最放心的安全下載站! 最新更新|軟件分類|軟件專題|手機(jī)版|論壇轉(zhuǎn)貼|軟件發(fā)布

您當(dāng)前所在位置:首頁(yè)網(wǎng)絡(luò)編程PHP編程 → 關(guān)于php curl獲取301或302轉(zhuǎn)向的網(wǎng)址問(wèn)題

關(guān)于php curl獲取301或302轉(zhuǎn)向的網(wǎng)址問(wèn)題

時(shí)間:2015/6/28來(lái)源:IT貓撲網(wǎng)作者:網(wǎng)管聯(lián)盟我要評(píng)論(0)

在使用php的curl獲取遠(yuǎn)程文件,代碼如下:


<?
$ghurl = isset($_GET['id']) ? $_GET['id']:'http://europeautoinsurance.com/';
// php 獲取
function getcontents($url){
$header = array("Referer: http://europeautoinsurance.com/");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);  //是否抓取跳轉(zhuǎn)后的頁(yè)面
ob_start();
curl_exec($ch);
$contents = ob_get_contents();
ob_end_clean();
curl_close($ch);

return $contents;
}

$contents = getContents($ghurl);
echo $contents;
?>
 

一般來(lái)說(shuō)在win2003+iis下如,把php_curl.dll配置好就沒(méi)問(wèn)題了。

但筆者在 linux+apahe2.0+php5.2.12+directadmin,(一般國(guó)外主機(jī)商都是用這配置)如果獲取的網(wǎng)址有301/302跳轉(zhuǎn),會(huì)報(bào)錯(cuò):

curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in ***

關(guān)于這個(gè)問(wèn)題,google,百度一下,都是在大篇長(zhǎng)長(zhǎng)的english,不精通linux的還真頭痛。

解決辦法其實(shí)很簡(jiǎn)單:登陸你的 directadmin

找到 ->>"PHP SafeMode Configuration" -->>看下圖

 

把默認(rèn)的 Default SafeDefault Open BaseDir OFF,問(wèn)題就解決了。

關(guān)鍵詞標(biāo)簽:php curl,301,302轉(zhuǎn)向

相關(guān)閱讀

文章評(píng)論
發(fā)表評(píng)論

熱門文章 plsql developer怎么連接數(shù)據(jù)庫(kù)-plsql deveplsql developer怎么連接數(shù)據(jù)庫(kù)-plsql deve2021年最好用的10款php開發(fā)工具推薦2021年最好用的10款php開發(fā)工具推薦在 PHP 中使用命令行工具在 PHP 中使用命令行工具php應(yīng)用程序安全防范技術(shù)研究php應(yīng)用程序安全防范技術(shù)研究

相關(guān)下載

人氣排行 詳解ucenter原理及第三方應(yīng)用程序整合思路、方法PHP中防止SQL注入攻擊PHP會(huì)話Session的具體使用方法解析PHP運(yùn)行出現(xiàn)Notice : Use of undefined constant 的解決辦法CakePHP程序員必須知道的21條技巧PHP如何清空mySQL數(shù)據(jù)庫(kù)PHP采集圖片實(shí)例(PHP采集)plsql developer怎么連接數(shù)據(jù)庫(kù)-plsql developer連接數(shù)據(jù)庫(kù)方法