PHP file stream simulation POST, GET pass value _ PHP Tutorial

Source: Internet
Author: User
Php file streams simulate POST and GET values. If we develop socialgame on facebook, we need to call its interface to obtain information about friends on facebook. At this time, we need to access an address provided by facebook. of course, if we develop social game on facebook, we need to call its interface to obtain information about friends of users on facebook. At this time, we need to access an address provided by facebook. of course, when you access him, he needs to verify your access to prevent illegal requests. At this time, you have to post to it | get some parameters.

Address:

$url_with_get= "http://api.facebook.com/restserver.php?method=facebook.friends.get&session_key=&api_key=1232121311&v=1.0";$post = array('sig'=>12312123234353);

How to get data from this address and briefly introduce the following code of the terminal:

if(function_exists('curl_init')){  $ch = curl_init();  curl_setopt($ch, CURLOPT_URL, $url_with_get);  curl_setopt($ch, CURLOPT_POST, 1);  curl_setopt($ch, CURLOPT_POSTFIELDS, $post);  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  $result = curl_exec($ch);  curl_close($ch);}else{  $content = http_build_query($post)  $content_length = strlen($content);  $context =        array('http' =>              array('method' => 'POST',                    'user_agent' => $user_agent,                    'header' => 'Content-Type: ' . $content_type . "\r\n" .                                'Content-Length: ' . $content_length,                    'content' => $content));    $context_id = stream_context_create($context);    $sock = fopen($url_with_get, 'r', false, $context_id);    $result = '';    if ($sock)  {    while (!feof($sock))           $result .= fgets($sock, 4096);        fclose($sock);    }    return $result;  }}

The above code uses two methods to call the facebook interface. The first method is to determine whether the curl Library is enabled in the user's environment. this method is used to obtain the request. For detailed parameter descriptions, refer to the manual. Note that we usually need to obtain the returned result of calling the interface, so we need to set the value of CURLOPT_RETURNTRANSFER to return the result to the variable.

The second method is to convert the url request into a file stream for processing.

Alibaba game, which needs to be called to obtain information about friends on facebook. At this time, we need to access an address provided by facebook. of course...

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.