Summary of php cross-server access methods and php cross-server access methods. Php cross-server access method summary, php cross-server summary this article examples summarizes the php cross-server access method. Share it with you for your reference. The specific analysis is as follows: a summary of php cross-server access methods in recent projects and a summary of php cross-server access
This example summarizes the php cross-server access method. Share it with you for your reference. The specific analysis is as follows:
Recently, cross-server access has been encountered in the project. after several days of research, it is summarized as follows:
1. use the file_get_contents method
$host = 'url'; $randomNumber=file_get_contents($host);echo $$randomNumber;
2. use Curl
$ Host = 'URL'; $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ host); // return result curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ($ ch, CURLOPT_HEADER, 0); // Use POST to submit curl_setopt ($ ch, CURLOPT_POST, 1); // POST parameter $ str = array ('a = 1 ', 'B = 2', 'C = 3'); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ str); // result $ res = curl_exec ($ ch ); curl_close ($ ch );
Before using the curl library, you may need to check php. ini to see if the curl extension has been enabled.
3. use fopen to open the url and get the content.
<?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 will help you with php programming.
Examples in this article summarize php cross-server access methods. Share it with you for your reference. The specific analysis is as follows: recently encountered projects...