php跨服务器访问方法小结,php跨服务器小结_PHP教程

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

php跨服务器访问方法小结,php跨服务器小结

本文实例总结了php跨服务器访问方法。分享给大家供大家参考。具体分析如下:

近来项目中遇到跨服务器访问的问题,研究了好些日子,总结如下:

1、用file_get_contents方法

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

2、用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

使用curl库,使用curl库之前,你可能需要查看一下php.ini,查看是否已经打开了curl扩展

3、 用fopen打开url, 以get方式获取内容

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

希望本文所述对大家的php程序设计有所帮助。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/998553.htmlTechArticlephp跨服务器访问方法小结,php跨服务器小结 本文实例总结了php跨服务器访问方法。分享给大家供大家参考。具体分析如下: 近来项目中遇...
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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!