Hey all,

Having some problems again. I have a login page that I'm trying to get to (and use) with cURL. Problem is that it won't login, and I'm blaming it on the cookies. I can go to the URL in my browser and it's fine, but for whatever reason, it doesn't work from my cURL script. It's also important to note that if I make my own login form, it'll work. But if I put that login form inside of an <iframe> on a webpage, it won't work.

Here's my code:

<?
$ch = curl_init("http://www.xxxxx.net/cgi-bin/xxxxx/login.cgi?id=xxxx&pw=xxxx");
$fp = fopen("get.txt", "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0");
curl_setopt($ch, CURLOPT_COOKIE, 'id=xxxx; pw=xxxx');
curl_setopt($ch, CURLOPT_COOKIEJAR, "curlcook.txt");

curl_exec($ch);
curl_close($ch);
fclose($fp);
include "get.txt";
?>

By the way, I'm not sure if the information being written to the cookie (in line curl_setopt($ch, CURLOPT_COOKIE, 'id=xxxx; pw=xxxx'); ) is necessary. Thanks...

edit: also note that creating a link to the URL in an HTML document will work fine.

    Try taking the space out of 'id=xxxx; pw=xxxx'. Cookie values are just seperated by a semicolon. I don't know how much of a problem a space would cause.

    As for the cookie jar, you might want to make sure its a valid file and it has read/write permissions (chmod 777). Even if its empty, that's ok (try "touch [cookie file name]" to create a blank file or just FTP up a blank file).

    Once you have the file in place, try the script. Then check the file to see if there's any saved cookies in it (FTP it down and use a editor). If you have something, then life is good. If you don't, then make sure the site is sending cookies. If it is, then you may have other problems...

      Write a Reply...