Php cross-server access method summary, php cross-server summary _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.