Home > Backend Development > PHP Tutorial > The perfect solution to request.querystring php error message failed to open stream: HTTP request failed!

The perfect solution to request.querystring php error message failed to open stream: HTTP request failed!

WBOY
Release: 2016-07-29 08:45:24
Original
989 people have browsed it

Google or Baidu, there are many such problems, the solution is to modify php.ini, enable allow_url_fopen, change allow_url_fopen = On
This can solve some people's problems, some people say that in php.ini, there is Two options: allow_url_fopen =on (indicates that remote files can be opened through url), user_agent="PHP" (indicates which script is used to access the network, by default there is a ";" in front of it and can be removed.) Restart the server.
But some people still have this warning message. There is still one step left to solve it perfectly. You have to set the user_agent in php.ini. The default user_agent in php is PHP. We change it to Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) to simulate the browser
user_agent=”Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)”
I encountered this problem at work and solved it perfectly, so I share it with everyone.
I grabbed the structural formula of chemblink in batches and found that some pictures could not be displayed after the loop, but the remote files existed.
When grabbing remote files, a warning message similar to Warning: readfile(http://www.jb51.net/logo.gif) [function.readfile]: failed to open stream: HTTP request failed! appears. I use Yes

Copy the code The code is as follows:


ob_start();
readfile("http://www.jb51.net/logo.gif");
$img = ob_get_contents();
ob_end_clean( );


The above error will appear from time to time during operation. I also changed other functions such as file_get_contents, but it didn't work. After checking on the Internet, I found that using the CURL method to capture will not go wrong
It is more popular to use curl now

Copy the code The code is as follows:


$url = "http://s.jb51.net";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url );
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,10);
$dxycontent = curl_exec($ch);
echo $dxycontent;
?>

The above introduces the perfect solution to the request.querystring PHP error message failed to open stream: HTTP request failed!, including the content of request.querystring. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template