A brief analysis of the workaround for the virtual Host server PHP fsockopen function _php Tutorial

Source: Internet
Author: User
First, how to disable Fsockopen ()
The following are two common ways to disable Fsockopen.
1, modify php.ini, will disable_functions = after adding fsockopen
2. Modify PHP.ini, change allow_url_fopen = on to Allow_url_fopen = Off

second, how to solve the Fsockopen function is disabled
1. If the server does not disable Pfsockopen at the same time, replace the Fsockopen function with Pfsockopen directly.
What to do: Search for string Fsockopen in the program (Replace with Pfsockopen (. Examples such as the following
Before modification:
$fp = Fsockopen ($host, $errno, $errstr, 30);
After modification:
$fp = Pfsockopen ($host, $errno, $errstr, 30);
2, if the server is also disabled pfsockopen, then use other functions instead, such as stream_socket_client (). Note: The parameters for Stream_socket_client () and Fsockopen () are different.
What to do: Search the program for string Fsockopen (replace with Stream_socket_client (, then, the port parameter "80" in the original Fsockopen function is deleted and added to the $host. Examples such as the following
Before modification:
$fp = Fsockopen ($host, $errno, $errstr, 30);
after modification
$fp = Stream_socket_client ($host. " ", $errno, $errstr, 30);
3, if the PHP version is less than 5.0,fsockopen is disabled, and no stream_socket_client () How to do? Write a function to implement Fsockopen function, reference code:
Copy CodeThe code is as follows:
function B_fsockopen ($host, $port, & $errno, & $errstr, $timeout) {
$ip = gethostbyname ($host);
$s = socket_create (af_inet, sock_stream, 0);
if (Socket_set_nonblock ($s)) {
$r = @socket_connect ($s, $ip, $port);
if ($r | | socket_last_error () = = einprogress) {
$errno = einprogress;
return $s;
}
}
$errno = Socket_last_error ($s);
$errstr = Socket_strerror ($errno);
Socket_close ($s);
return false;
}

Operation: 1. First find the code snippet that uses the Fsockopen function, add the above code to its upper end, and search for the string fsockopen in the snippet (replace with B_fsockopen (.
2. Because the Fsockopen function returns a file pointer so it can be manipulated by the file function, but this b_fsockopen function does not return the file pointer, you need to continue to modify the code snippet: with Socket_read (replace Fread (, with Socket_write ( Replace the fwrite (, with Socket_close (replace the fclose (.

http://www.bkjia.com/PHPjc/328145.html www.bkjia.com true http://www.bkjia.com/PHPjc/328145.html techarticle first, how to disable Fsockopen () The following are two common ways to disable Fsockopen. 1, modify php.ini, will disable_functions = after adding Fsockopen 2, modify PHP.ini, will allow_url_ ...

  • Related Article

    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.