Ucenter Home does not support Fsockopen but supports ucenter and modoer communication problems under CULR environment

Source: Internet
Author: User
So it is doubtful whether the coding problem, or the file permissions problem, or is not the function of the problem, after the investigation found that the original is WAN L1 host does not support Fsockopen, in the file uc_client/client.php Uc_fopen in the problem occurred, The code here is this:

Copy the Code code as follows:


function Uc_fopen ($url, $limit = 0, $post = ", $cookie =", $bysocket = FALSE, $ip = ", $timeout = A, $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 function can not be used, because some can only rely on other methods, thanks to support curl,file_get_contents also support, after consideration with Curl Bar, modified the Uc_fopen function, as follows;

Copy the Code code as follows:


Function Uc_fopen ($url, $limit = 0, $post = ", $cookie =", $bysocket = FALSE, $ip = ", $timeout = a, $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 '

  Error:  
'. Curl_error ($curl);
}
Curl_close ($curl);
return $return;
}


So modoer under the uc_client/client.php and Uchome under the uc_cilent/client.php, so modify the Uc_open function, hehe, the first time using curl, The information on the Internet is still a lot of, so there is no hindrance, but I do not know whether this change will affect other things, but also to test Luo ....

The above describes the Ucenter home does not support Fsockopen but support CULR environment under Ucenter and modoer communication issues, including Ucenter home aspects of the content, I hope that the PHP tutorial interested friends have helped Help.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.