SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing cookies through curl?

    I am trying to access information on facebook via curl that can only be accessed when logged in. I am assuming this means I need to pass a cookie through curl, correct? So far the only information I can find about using cookies with curl is that CURLOPT_cookieJAR is for storing cookies and CURLOPT_cookieFILE is for sending back cookies... does that mean I have to create a file with the cookie and put it on my server, and then call that file with CURLOPT_cookieFILE, like so?:

    Code:
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_COOKIEFILE, "cookiefile");
    If so, how do I know what the cookie contents are?
    Also, I believe facebook uses sessions... how do I include the session information in the cookie so that it will work?

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Presumably the first request you send is to login. During the login process, you will probably get some cookies back, like a session cookie for example.

    You might get some cookies on the inital page request, and/or maybe after submitting the valid user/pass.

    Once you have them, you can make further requests and the server should allow them assuming you send the proper cookies back along with them.

    the cookiejar is where curl will store cookies that came back as the result of the request. the cookiefile is where it will read them from when sending a request. So, you generally will use the same file for both. Take a look at the tempnam() to get a good unique filename to use.

    Consider using something like live http headers addon for firefox, or firebug etc... to get an idea of what headers/cookies are sent and when. You might need to also duplicate other headers in order to appear "real" to the other server.


Bookmarks

Posting Permissions

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