Results 1 to 8 of 8

Thread: PHP Api Question(s)

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Posts
    16

    PHP Api Question(s)

    Hello VBForums, i haven't been on here for awhile, like to say i hope everyone had a good xmas and new year...

    My question is about PHP classes and API's.

    So i'm looking into PHP classes and API's, i downloaded the facebook API file from the link given to github (http://github.com/facebook/php-sdk). After looking at the class/API file (facebook.php and https://github.com/facebook/php-sdk/...c/facebook.php) what i don't understand is, how it works server sided, i sort of understand some of the code but not all of it as i'm still in the process of learning PHP classes.

    I don't understand, despite the sheer amount of tutorials i've read on classes/PHP API'S, how it works on the server side, because it isn't exposing any more code than what it wants, for example say if there is code in the class to check whether the developer/user is authorised, does it expose the database code to retrieve the user and information from the database in the code? because i don't see that as there is no database information whatsoever in the facebook.php file, also wouldn't that expose facebook/whatever site to major security risks exposing the database information?

    Sorry if you don't understand this post, i'm not the best at explaining.

    Thanks.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: PHP Api Question(s)

    Facebook exposes a web service which you can call by making HTTP requests (just like the ones you make to read and post to this forum).
    The Facebook API file that you've got is a class which represents the API. When you call one of its methods it makes the appropriate request for data and returns the result. This is all a convenience, so that you can treat Facebook as being like any other class in your PHP application.
    The actual database connection only happens on Facebook's servers when a request is received over HTTP (from a web client, mobile client, or web service client). Databases are never exposed over the web.

    Does that make sense?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Posts
    16

    Re: PHP Api Question(s)

    Quote Originally Posted by penagate View Post
    Facebook exposes a web service which you can call by making HTTP requests (just like the ones you make to read and post to this forum).
    The Facebook API file that you've got is a class which represents the API. When you call one of its methods it makes the appropriate request for data and returns the result. This is all a convenience, so that you can treat Facebook as being like any other class in your PHP application.
    The actual database connection only happens on Facebook's servers when a request is received over HTTP (from a web client, mobile client, or web service client). Databases are never exposed over the web.

    Does that make sense?
    Thanks for replying.

    Oh right ok, it sort of makes sense... what i don't understand how it works, for example say i call the class /function "is_logged_in" how does that work on the server side? What i mean is, how does the server recieve someone has requested the "is_logged_in" function?

    because i know how it works using forms...for example:

    api.php?cmd=isloggedin

    and then in api.php
    if($_GET['cmd']==isloggedin)
    {
    //do the checks
    }
    i understand how you'd do that to check whether the user is logged in - but in the facebook.php file, no links are exposed whatsoever...so how does it know "where to go" ?

    Then, how can you return the data using variables because aren't they locally held?
    such as on api.php $username, you can go echo $username - but how do you do that when you aren't the servers?

    for example on this forum there is proably a $username variable and only this forum / files can access it because it's a local variable, and even if it's declarded global - that doesn't mean (literally) the world can access it, right? so how would a 3rd party such as me, retrieve the variable $username ?

    Does this make any sense? sorry if it doesn't...

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: PHP Api Question(s)

    Look at the 'api' function in the Facebook class. Follow the code there. It builds a HTTP request and sends it using cURL.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Posts
    16

    Red face Re: PHP Api Question(s)

    Quote Originally Posted by penagate View Post
    Look at the 'api' function in the Facebook class. Follow the code there. It builds a HTTP request and sends it using cURL.
    Thanks for replying again.

    I cannot believe i missed that, i feel so stupid. I've re-read the facebook.php and although i only understand some of it, i'm still not sure how it's sending the request but i'm going to re-read tutorials on classes and re-study this facebook.php and try and make some sense out of it.

    Also why does some classes use Curl? Because i was reading some tutorials on classes, and some didn't use Curl...

    Thanks

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: PHP Api Question(s)

    cURL (Client URL Library) is a library for making HTTP requests. It's not anything specific to classes (nor does it actually use classes). It's often used, as in this case, to communicate with a remote server.

    There are other, more simple ways of fetching data over HTTP from PHP. For example, you can use the file_get_contents function to read the response into a string.
    cURL is used in this case because it supports things like cookies and file uploading which the API makes use of.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Posts
    16

    Re: PHP Api Question(s)

    Quote Originally Posted by penagate View Post
    cURL (Client URL Library) is a library for making HTTP requests. It's not anything specific to classes (nor does it actually use classes). It's often used, as in this case, to communicate with a remote server.

    There are other, more simple ways of fetching data over HTTP from PHP. For example, you can use the file_get_contents function to read the response into a string.
    cURL is used in this case because it supports things like cookies and file uploading which the API makes use of.
    Oh right i understand now, so it sort of combines the functions of get/post - but for classes?, if you understand what i mean.

  8. #8
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: PHP Api Question(s)

    No, it's got nothing to do with classes. Classes are just for organising code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width