Space does not support the fsockopen function solution. I bought a space today and found that the space does not support the fsockopen function. then I found several solutions on the Internet that do not support the fsockopen method. I will share with you the following, I hope you have bought a space today and found that the space does not support the fsockopen function. later, I found several solutions on the Internet that do not support the fsockopen method. I would like to share with you the following, I hope it will help you.
For server security considerations, many host vendors disabled the fsockopen function of php. They blog yesterday and use cos-html-cache to generate static files. Nima prompts:
Warning: fsockopen () has been disabled for security reasons in D:... cos-html-cachecos-html-cache.php on line 35
Cos-html-cache of other versions is not supported. Then find the following method. =, (The result is invalid because the functions are disabled .)
We have tried to replace functions with other methods.
1. how to disable fsockopen ()
The following are two common methods to disable fsockopen.
1. modify php. ini and add disable_functions = to fsockopen.
2. modify php. ini and change allow_url_fopen = On to allow_url_fopen = Off.
II. how to disable the fsockopen function
1. if the server does not disable pfsockopen at the same time, replace the fsockopen function with pfsockopen.
Specific operation: Search for the string fsockopen in the program (replace with pfsockopen (. Example:
Before modification:
The code is as follows: |
|
$ Fp = fsockopen ($ host, 80, $ errno, $ errstr, 30 ); After modification: $ Fp = pfsockopen ($ host, 80, $ errno, $ errstr, 30 ); |
2. if pfsockopen is disabled on the server, use other functions, such as stream_socket_client (). Note: the parameters of stream_socket_client () and fsockopen () are different.
Specific operation: Search for the character string fsockopen in the program (replace it with stream_socket_client (, and then delete the port parameter "80" in the original fsockopen function and add it to $ host. Example:
Before modification:
The code is as follows: |
|
$ Fp = fsockopen ($ host, 80, $ errno, $ errstr, 30 ); After modification $ Fp = stream_socket_client ($ host. "80", $ errno, $ errstr, 30 ); |
3. what if fsockopen is disabled and stream_socket_client () is not available if PHP version is earlier than 5.0? Write a function to implement the fsockopen function. refer to the code:
The 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 operations:
1. first find the code segment that uses the fsockopen function, add the code above to its upper end, search for the string fsockopen in the code segment (replace it with B _fsockopen (
.
2. because the fsockopen function returns the file pointer, it can be operated by the file function, but this B _fsockopen function does not return the file pointer. you need to modify the code segment: use socket_read (replace fread (, use socket_write (replace fwrite (and use socket_close (replace fclose (.
Solution 2:
Most fsockopen applications obtain remote page data. for applications that obtain remote pages, PHP has other functions that can be perfectly replaced:
Method 1:
The code is as follows: |
|
$ Str = file ("http://www.bKjia. c0m "); $ Count = count ($ str ); For ($ I = 0; $ I <$ count; $ I ++ ){ $ File. = $ str [$ I]; } Echo $ file; ?>
|
Method 2:
The code is as follows: |
|
$ Str = file_get_contents ("http://www.bKjia. c0m "); Echo $ str; ?> |
...