PHP cross-server access method Summary, PHP cross-server summary
This article summarizes the PHP cross-server access method. Share to everyone for your reference. The specific analysis is as follows:
Recent projects encountered cross-server access issues, studied a number of days, summarized as follows:
1. Using file_get_contents method
$host = ' url '; $randomNumber =file_get_contents ($host); echo $ $randomNumber;
2, with Curl
$host = ' url '; $ch = Curl_init (); curl_setopt ($ch, Curlopt_url, $host); The results were curl_setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($ch, Curlopt_header, 0); Use POST to submit curl_setopt ($ch, Curlopt_post, 1); Post Parameters $str = Array (' a=1 ', ' b=2 ', ' c=3 '); curl_setopt ($ch, Curlopt_postfields, $STR);//Results $res = curl_exec ($ch); Curl_close ($ch);
With the Curl Library, you may need to look at php.ini to see if the curl extension has been turned on before using the Curl Library.
3. Open the URL with fopen and get the content in Get mode
<?php$url= "http://www.bkjia.com/"; $fp =fopen ($url, ' R '), while (!feof ($fp)) {$result. =fgets ($FP, 1024);} echo "$result"; fclose ($FP);? >
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/998553.html www.bkjia.com true http://www.bkjia.com/PHPjc/998553.html techarticle PHP cross-Server access method Summary, PHP cross-server Summary This article summarizes the PHP cross-server access method. Share to everyone for your reference. The specific analysis is as follows: Recent projects encountered ...