PHP cross-server access method Summary, PHP cross-server Summary _php tutorial

Source: Internet
Author: User

PHP cross-server access method Summary, PHP cross-server summary


This article summarizes the PHP cross-server access method. Share to everyone for your reference. 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.bkjia.com/"; $fp =fopen ($url, ' R '), while (!feof ($fp)) {$result. =fgets ($FP, 1024);} echo "$result"; fclose ($FP);? >

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/998553.html www.bkjia.com true http://www.bkjia.com/PHPjc/998553.html techarticle PHP cross-Server access method Summary, PHP cross-server Summary This article summarizes the PHP cross-server access method. Share to everyone for your reference. The specific analysis is as follows: Recent projects encountered ...

  • 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.