Home > Backend Development > PHP Tutorial > Summary of php cross-server access methods, summary of php cross-server_PHP tutorial

Summary of php cross-server access methods, summary of php cross-server_PHP tutorial

WBOY
Release: 2016-07-13 09:54:11
Original
1107 people have browsed it

Summary of PHP cross-server access methods, PHP cross-server summary

The examples in this article summarize PHP cross-server access methods. Share it with everyone for your reference. The specific analysis is as follows:

Recently, I encountered the problem of cross-server access in the project. I have been studying it for several days and the summary is as follows:

1. Use file_get_contents method

$host = 'url'; 
$randomNumber=file_get_contents($host);
echo $$randomNumber;
Copy after login

2. Use Curl

$host = 'url'; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $host); 
// 返回结果 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0); 
// 使用POST提交 
curl_setopt($ch, CURLOPT_POST, 1); 
// POST参数 
$str = array('a=1','b=2','c=3'); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
// 结果 
$res = curl_exec($ch); 
curl_close($ch);
Copy after login

Use the curl library. Before using the curl library, you may need to check php.ini to see if the curl extension has been turned on

3. Use fopen to open the url and get the content using get method

<&#63;php
$url="http://www.bkjia.com/";
$fp=fopen($url,'r');
while(!feof($fp)){
$result.=fgets($fp,1024);
}
echo" $result";
fclose($fp);
&#63;>
Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/998553.htmlTechArticleSummary of php cross-server access methods, php cross-server summary This article summarizes php cross-server access methods through examples. Share it with everyone for your reference. The specific analysis is as follows: In recent projects, I encountered...
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