[5.2.2/cURL] Not getting cookies?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

    So I'm trying to use cURL to write a PHP5 script that is effectively
a proxy, since the browser will call this index.php which will fetch
pages from a remote server, and pass them on to the browser, including

For some reason, cURL fails creating the file that holds cookies
("CookieJar not created!"), although I copy/pasted this code from
cURL's web site
(http://curl.haxx.se/libcurl/php/examples/cookiejar.html ):

    //Using one script for different steps
    $status = ($_POST['status']? $_POST['status'] : $_GET['status']);
    switch($status) {
        //Show login page
            //Form in text file
            $page = file_get_contents("login.tpl");
            echo $page;

        case "login":
            //POST params to remote web server
            $login = $_POST['Login'];
            $password = $_POST['Password'];
            $cookiefile = $login . ".txt";

            if (isset($login) and file_exists($cookiefile)) {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
            curl_setopt($ch, CURLOPT_URL,"http://www.acme.com/connect.php ");
            curl_setopt($ch, CURLOPT_POST, 1);
            $data = sprintf("Login=%s&Password=%s",$login,$password);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            ob_start();      // prevent any output
            $buffer = curl_exec ($ch); // execute the curl command
            ob_end_clean();  // stop preventing output
            curl_close ($ch);

            //HERE : why isn't cookie file created?

            if(!file_exists($cookiefile)) {
                echo "CookieJar not created!";
            } else {
                $cookiejar = file_get_contents($cookiefile);
                echo $cookiejar;

            //Now, fetch main page
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
            curl_setopt($ch, CURLOPT_URL,"http://www.acme.com /");
            $buf2 = curl_exec ($ch);
            curl_close ($ch);
            echo "<PRE>".htmlentities($buf2);

Any idea what cURL wouldn't happily POST login + password and get an
reply with the HTTP header containing cookies?

Thank you for any tip.

Re: [5.2.2/cURL] Not getting cookies?

Quoted text here. Click to load it

For those interested, the issue was that cURL expects a full-qualified
path to the cookie file, instead of a relative one:

$cookiefile = getcwd() . "\" . $login . ".txt";


Site Timeline