This article mainly introduces the PHP cross-server access method, the example summarizes the common PHP cross-server access skills. We hope to help you.
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.jb51.net/"; $fp =fopen ($url, ' R '), while (!feof ($fp)) {$result. =fgets ($FP, 1024);} echo "$result"; fclose ($FP);? >
Related recommendations:
The method of cross-domain in JS
A detailed analysis of cross-domain solutions in laravel development
Ajax principle and the method of Cors cross-domain