Proactive System Password Reco PHP analog post| Get Operation Implementation Code

Source: Internet
Author: User
Recently developed social game, found that the use of this thing is still relatively ordinary, here to make a summary, one for their own memory, but also hope that everyone has help.
First look at the demand, if we develop social game on Facebook, we need to call its interface to get the user's friend information on Facebook. At this point we're going to visit an address provided by Facebook, and of course when you visit him, he needs to verify your visit and prevent illegal requests. At this point you have to post|get some parameters to it.
As the following address:

Copy the Code code as follows:


$url _with_get= "Http://api.facebook.com/restserver.php?method=facebook.friends.get&sessi
$post = Array (' sig ' =>12312123234353);


How to get data from this address, simply introduce the following code:

Copy the Code code as follows:


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 ways to tune the interface of Facebook, the first county to determine whether the user's environment opens the Curl Library, opened the library, in this way to obtain the request. Inside the detailed parameters explained that you can refer to the manual.
It is suggested here that since we usually need to get the return result of the calling interface, we want to set the value of Curlopt_returntransfer and return the result to the variable.
The second approach is intuitive, translating URL requests into file streams for processing.

The above describes the proactive system password Reco PHP simulation post| Get operation implementation code, including the proactive system password Reco aspects of the content, I hope to be interested in PHP tutorial friends helpful.

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