cURL returns please enable cookies?

11,135

Solution 1

Well their cloudflare system was just blocking the IP of my server (it was a shared one), getting a new host with its own IP solved the issue... Thank you for your time guys, appreciated it.

Solution 2

curl has a full cookie "engine" built in.
If you activate it, you can have curl receive and send cookies like a browser does.

Command line options:

-b, --cookie

tell curl a file to read cookies from and start the cookie engine, or if it isn't a file it will pass on the given string. -b name=var works and so does -b cookiefile.

-j, --junk-session-cookies

when used in combination with -b, it will skip all "session cookies" on load so as to appear to start a new cookie session.

-c, --cookie-jar

tell curl to start the cookie engine and write cookies to the given file after the request(s)

Ref: https://curl.haxx.se/docs/http-cookies.html

Share:
11,135
rilent
Author by

rilent

Do many things at the same time.

Updated on June 15, 2022

Comments

  • rilent
    rilent almost 2 years

    It seems like I need some help to set up my cURL, I am trying to do API calls to an external website from my server. What bugs me is that sometimes this code works and return the expected result, but sometimes It returns this message :

    enter image description here

    Here is my code :

    $path_cookie = 'cookie.txt';
    if (!file_exists(realpath($path_cookie))) touch($path_cookie);
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, "http://www.example.com/api/findusers/".$nick_list."?key=".$voobly_key);
    curl_setopt($ch, CURLOPT_COOKIESESSION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_COOKIEJAR, realpath($path_cookie));
    $headers = [
            'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
            'cookie: __cfduid=d0d14dfd36e0da8e7858b58873b4263181523751395'
    ];
    
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    
    
    $response = curl_exec($ch);
    curl_close($ch);
    echo "rep : $response";
    

    Is the problem on my side or the problem could come from the external server?

    My cookie.txt looks like this :

    # Netscape HTTP Cookie File
    # http://curl.haxx.se/rfc/cookie_spec.html
    # This file was generated by libcurl! Edit at your own risk.
    
    #HttpOnly_.example.com  TRUE    /   FALSE   1555287395  __cfduid    d0d14dfd36e0da8e7858b58873b4263181523751395
    
  • Spoody
    Spoody almost 6 years
    I'm not sure how is this related to PHP cURL
  • wp78de
    wp78de almost 6 years
    Sorry, you may want to try that instead: github.com/agusl88/VooblyAPI-PHP-Wrapper
  • user
    user over 3 years
    Can you give command-line usage examples for each option?