PHP fsockopen, Pfsockopen functions are disabled by the host vendor, Fsockopen function _php Tutorial

Source: Internet
Author: User

PHP fsockopen, Pfsockopen functions are disabled by the host vendor, Fsockopen function


Perhaps Fsockopen, Pfsockopen function There is a security risk, but we have no research, this is the IDC business, whatever the reason, anyway, they are to disable the two functions, then how to solve, the following is a small compilation method, Hope to use the students have a certain reference.

Here's how to fix it:

First, using stream_socket_client () instead

The server also disables Fsockopen, Pfsockopen, and other functions instead, such as stream_socket_client (). Note: The parameters for Stream_socket_client () and Fsockopen () are different.

Specific operation:

Search for the string in the program Fsockopen (replace with Stream_socket_client (, then, the port parameter "80" in the original Fsockopen function is deleted and added to the $host.

Examples are as follows:

Before modification:

Copy the Code code as follows: $fp = Fsockopen ($host, $errno, $errstr, 30);

Or

Copy the code as follows: $fp = Fsockopen ($host, $port, $errno, $errstr, $connection _timeout);

After modification:

Copy the code as follows: $fp = Stream_socket_client ("tcp://". $host. " 80″, $errno, $errstr, 30);

Or

Copy the code as follows: $fp = Stream_socket_client ("tcp://". $host. ":". $port, $errno, $errstr, $connection _timeout);

Second, rewrite the law

What if the PHP version is lower than 5.0,fsockopen is disabled and no stream_socket_client ()? Write a function to implement Fsockopen function, reference code:
Copy the Code code 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;

}

Specific operation:

1. First locate 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 (.

In the above method, I use Stream_socket_client () instead of solving the problem, the second method did not try.


Win's host disabled the function Fsockopen and Pfsockopen, can not invoke the API, how to solve?

I'll give you the address.

How does the WordPress program installed on the virtual host change the Fsockopen pfsockopen function to disable?

Modify Fsockopen Pfsockopen is required to modify the PHP configuration file php.ini, the file is a PHP program files, placed in the PHP directory, not a wordpress file.

WordPress is the use of PHP parsing of a web-based program, he relies on the function must be supported by PHP, to change the configuration of PHP, please go to the directory where PHP found php.ini to modify.

http://www.bkjia.com/PHPjc/840756.html www.bkjia.com true http://www.bkjia.com/PHPjc/840756.html techarticle php fsockopen, Pfsockopen function by the host to disable the solution, Fsockopen function may Fsockopen, pfsockopen function There is indeed a security risk, but we have no test ...

  • 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.