不支持fsockopen但支持culr環(huán)境下下ucenter與modoer通訊問題
更新時間:2011年08月12日 16:20:30 作者:
網(wǎng)站上線,modoer與ucenter 下不能通訊折騰了我差不多二天,開始都以為自己的配置出問題,移植了平臺后就不能通訊了,修改了幾次配置,都沒有成功
所以就懷疑是否編碼問題,或者文件權(quán)限問題,或者是不是函數(shù)不支持問題,經(jīng)過排查發(fā)現(xiàn)原來是萬網(wǎng)的L1主機不支持fsockopen,在文件uc_client/client.php中的uc_fopen中出現(xiàn)了問題,這里的代碼是這樣:
function uc_fopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE) {
$return = '';
$matches = parse_url($url);
!isset($matches['host']) && $matches['host'] = '';
!isset($matches['path']) && $matches['path'] = '';
!isset($matches['query']) && $matches['query'] = '';
!isset($matches['port']) && $matches['port'] = '';
$host = $matches['host'];
$path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/';
$port = !empty($matches['port']) ? $matches['port'] : 80;
if($post) {
$out = "POST $path HTTP/1.0\r\n";
$out .= "Accept: */*\r\n";
//$out .= "Referer: $boardurl\r\n";
$out .= "Accept-Language: zh-cn\r\n";
$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
$out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
$out .= "Host: $host\r\n";
$out .= 'Content-Length: '.strlen($post)."\r\n";
$out .= "Connection: Close\r\n";
$out .= "Cache-Control: no-cache\r\n";
$out .= "Cookie: $cookie\r\n\r\n";
$out .= $post;
} else {
$out = "GET $path HTTP/1.0\r\n";
$out .= "Accept: */*\r\n";
//$out .= "Referer: $boardurl\r\n";
$out .= "Accept-Language: zh-cn\r\n";
$out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
$out .= "Host: $host\r\n";
$out .= "Connection: Close\r\n";
$out .= "Cookie: $cookie\r\n\r\n";
}
$fp = @fsockopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout);
if(!$fp) {
return '';//note $errstr : $errno \r\n
} else {
stream_set_blocking($fp, $block);
stream_set_timeout($fp, $timeout);
@fwrite($fp, $out);
$status = stream_get_meta_data($fp);
if(!$status['timed_out']) {
while (!feof($fp)) {
if(($header = @fgets($fp)) && ($header == "\r\n" || $header == "\n")) {
break;
}
}
$stop = false;
while(!feof($fp) && !$stop) {
$data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
$return .= $data;
if($limit) {
$limit -= strlen($data);
$stop = $limit <= 0;
}
}
}
@fclose($fp);
return $return;
}
}
fsockopen函數(shù)不能使用,因些就只能靠其它方法了,幸虧支持curl,file_get_contents也支持,經(jīng)考慮就用curl吧,修改了uc_fopen函數(shù),如下;
function uc_fopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE) {
$return = '';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
if($post) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
}
if($cookie) {
curl_setopt($curl, CURLOPT_COOKIE, $cookie);
}
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($curl);
if (curl_errno($curl)) {
echo '<pre><b>錯誤:</b><br />'.curl_error($curl);
}
curl_close($curl);
return $return;
}
于是modoer下的uc_client/client.php和uchome下的uc_cilent/client.php,就這樣修改了uc_open函數(shù),呵呵,第一次使用curl,網(wǎng)上的資料還是好多的,所以也沒有什么阻礙,不過就不知這個修改會不會影響其它的東西,還有待測試羅。。。。
復(fù)制代碼 代碼如下:
function uc_fopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE) {
$return = '';
$matches = parse_url($url);
!isset($matches['host']) && $matches['host'] = '';
!isset($matches['path']) && $matches['path'] = '';
!isset($matches['query']) && $matches['query'] = '';
!isset($matches['port']) && $matches['port'] = '';
$host = $matches['host'];
$path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/';
$port = !empty($matches['port']) ? $matches['port'] : 80;
if($post) {
$out = "POST $path HTTP/1.0\r\n";
$out .= "Accept: */*\r\n";
//$out .= "Referer: $boardurl\r\n";
$out .= "Accept-Language: zh-cn\r\n";
$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
$out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
$out .= "Host: $host\r\n";
$out .= 'Content-Length: '.strlen($post)."\r\n";
$out .= "Connection: Close\r\n";
$out .= "Cache-Control: no-cache\r\n";
$out .= "Cookie: $cookie\r\n\r\n";
$out .= $post;
} else {
$out = "GET $path HTTP/1.0\r\n";
$out .= "Accept: */*\r\n";
//$out .= "Referer: $boardurl\r\n";
$out .= "Accept-Language: zh-cn\r\n";
$out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
$out .= "Host: $host\r\n";
$out .= "Connection: Close\r\n";
$out .= "Cookie: $cookie\r\n\r\n";
}
$fp = @fsockopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout);
if(!$fp) {
return '';//note $errstr : $errno \r\n
} else {
stream_set_blocking($fp, $block);
stream_set_timeout($fp, $timeout);
@fwrite($fp, $out);
$status = stream_get_meta_data($fp);
if(!$status['timed_out']) {
while (!feof($fp)) {
if(($header = @fgets($fp)) && ($header == "\r\n" || $header == "\n")) {
break;
}
}
$stop = false;
while(!feof($fp) && !$stop) {
$data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
$return .= $data;
if($limit) {
$limit -= strlen($data);
$stop = $limit <= 0;
}
}
}
@fclose($fp);
return $return;
}
}
fsockopen函數(shù)不能使用,因些就只能靠其它方法了,幸虧支持curl,file_get_contents也支持,經(jīng)考慮就用curl吧,修改了uc_fopen函數(shù),如下;
復(fù)制代碼 代碼如下:
function uc_fopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE) {
$return = '';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
if($post) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
}
if($cookie) {
curl_setopt($curl, CURLOPT_COOKIE, $cookie);
}
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($curl);
if (curl_errno($curl)) {
echo '<pre><b>錯誤:</b><br />'.curl_error($curl);
}
curl_close($curl);
return $return;
}
于是modoer下的uc_client/client.php和uchome下的uc_cilent/client.php,就這樣修改了uc_open函數(shù),呵呵,第一次使用curl,網(wǎng)上的資料還是好多的,所以也沒有什么阻礙,不過就不知這個修改會不會影響其它的東西,還有待測試羅。。。。
您可能感興趣的文章:
- destoon整合ucenter后注冊頁面不跳轉(zhuǎn)的解決方法
- destoon整合UCenter圖文教程
- codeigniter集成ucenter1.6雙向通信的解決辦法
- 單點登錄 Ucenter示例分析
- 關(guān)于shopex同步ucenter的redirect問題,導(dǎo)致script不運行
- UCenter 批量添加用戶的php代碼
- UCenter info: MySQL Query Error SQL:SELECT value FROM [Table]vars WHERE noteexists
- UCenter中的一個可逆加密函數(shù)authcode函數(shù)代碼
- php將會員數(shù)據(jù)導(dǎo)入到ucenter的代碼
- UCenter Home二次開發(fā)指南
- 簡單分析ucenter 會員同步登錄通信原理
相關(guān)文章
php中把對象轉(zhuǎn)換為數(shù)組幾種簡單巧妙的方法
在PHP中,對象是一種復(fù)雜的數(shù)據(jù)類型,它可以包含多個屬性和方法,有時候我們需要將對象轉(zhuǎn)換為數(shù)組進(jìn)行操作,比如將對象存儲到數(shù)據(jù)庫中,或者將對象轉(zhuǎn)換為JSON格式等情況,對象轉(zhuǎn)數(shù)組不能用遞歸實現(xiàn)轉(zhuǎn)換,本文幾種簡單巧妙的方法2023-09-09phpinfo()中Loaded Configuration File(none)的解決方法
這篇文章主要給大家介紹了phpinfo()中Loaded Configuration File(none)問題的解決方法,需要的朋友可以參考借鑒,下面來一起看看吧。2017-01-01php實現(xiàn)專業(yè)獲取網(wǎng)站SEO信息類實例
這篇文章主要介紹了php實現(xiàn)專業(yè)獲取網(wǎng)站SEO信息類,實例分析了seoreport類針對網(wǎng)站SEO信息檢查與獲取的技巧,非常具有實用價值,需要的朋友可以參考下2015-04-04PHPExcel實現(xiàn)表格導(dǎo)出功能示例【帶有多個工作sheet】
這篇文章主要介紹了PHPExcel實現(xiàn)表格導(dǎo)出功能,結(jié)合實例形式分析了PHPExcel針對帶有多個工作sheet的表格導(dǎo)出相關(guān)操作實現(xiàn)技巧,需要的朋友可以參考下2018-06-06