PHP for cross-server access

Source: Internet
Author: User
This article mainly introduces the PHP cross-server access method, the example summarizes the common PHP cross-server access skills. We hope to help you.

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.jb51.net/"; $fp =fopen ($url, ' R '), while (!feof ($fp)) {$result. =fgets ($FP, 1024);} echo "$result"; fclose ($FP);? >

Related recommendations:

The method of cross-domain in JS

A detailed analysis of cross-domain solutions in laravel development

Ajax principle and the method of Cors cross-domain

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.