Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that the virtual host server php fsockopen function is disabled

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to solve the problem that the php fsockopen function of the virtual host server is disabled", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to solve the problem that the php fsockopen function of the virtual host server is disabled.

How to disable fsockopen ()

Here are two common ways to disable fsockopen.

1. Modify php.ini and add disable_functions = to fsockopen

2. Modify php.ini to change allow_url_fopen = On to allow_url_fopen = Off

Second, how to solve the problem that fsockopen function is disabled

1. If the server does not disable pfsockopen at the same time, replace the fsockopen function with pfsockopen directly.

Specific operation: search for the string fsockopen in the program (replace with pfsockopen (. Examples are as follows

Before modification:

$fp = fsockopen ($host, 80, $errno, $errstr, 30)

After modification:

$fp = pfsockopen ($host, 80, $errno, $errstr, 30)

2. If the server also disables pfsockopen, replace it with other functions, such as stream_socket_client (). Note: the parameters of stream_socket_client () and fsockopen () are different.

What to do: search for the string fsockopen in the program (replace it with stream_socket_client (), then delete the port parameter "80" from the original fsockopen function and add it to $host. Examples are as follows

Before modification:

$fp = fsockopen ($host, 80, $errno, $errstr, 30)

After modification

$fp = stream_socket_client ($host. "80", $errno, $errstr, 30)

3. What if the PHP version is less than 5.0 and fsockopen is disabled without stream_socket_client ()? Write a function to implement the function of fsockopen. Refer to the code:

The copy 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

}

Specific operation: 1. First find the code snippet that uses the fsockopen function, add the above code to it, and search for the string fsockopen in the code snippet (replace with b_fsockopen (.)

two。 Because the fsockopen function returns the file pointer, it can be operated by the file function, but the b_fsockopen function fails to return the file pointer and needs to continue to modify the code snippet: socket_read (replace fread (, replace socket_write (replace fwrite (), replace fclose ().

At this point, I believe you have a deeper understanding of "how to solve the problem that the php fsockopen function of the virtual host server is disabled". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report