Home >Backend Development >PHP Tutorial >PHP uses file_get_contents instead of using curl instance, curlgetcontents_PHP tutorial
The example in this article describes the method of using file_get_contents in PHP instead of using curl. I would like to share it with you for your reference. The specific implementation method is as follows:
It is actually rare to use file_get_contents instead of curl, but sometimes when you encounter that the server does not support curl, we can use file_get_contents instead of curl. Let’s look at an example.
When you try all means to find that the server really cannot use curl. Or when curl does not support https. When curl https appears 502. When you don't want to reinstall the website environment, you can use file_get_contents instead.
curl commonly used curl get curl post
Instead of curl get, just use file_get_contents($url)
curl post replacement is as follows:
I hope this article will be helpful to everyone’s PHP programming design.
Simulate a header information
array( 'method'=>"GET", 'header'=>"User-Agent: " .$_SERVER['HTTP_USER_AGENT']."\r\n" ) ); $context = stream_context_create($opts); $url = dynamic.12306.cn/...0$data = file_get_contents($url,null, $context);echo $data;?> That’s it
Purely automatic entry, or manual entry with manual help. It would be much easier if done manually. It is nothing more than writing a regular expression to get the URL and title of the page
. If it is purely automatic, you must write a program to simulate your normal access to
. When you reach the first page, a POST request is sent, and you need to send the corresponding parameters
Make a POST request, and then intercept the corresponding needs from the page. When you want to access the second version, send
as a GET request. At this time, you need to send parameters to the bar in the same way until the tenth page. There are
similar reptiles on the PHP pipe network, go to the next one, it is very convenient