tags:

views:

215

answers:

2

This is my code:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://www.membersite.com/login.php");
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'username=deleted&password=deleted');
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'C:\xampp\htdocs\scrape\cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$store = curl_exec ($ch);

curl_setopt($ch, CURLOPT_URL, "http://www.membersite.com/memberlist.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$page = curl_exec ($ch);

echo $page;

curl_close($ch);

But I don't think it's successfully logging in as the site (my own, by the way) doesn't show a log of me signing in. I know the username and password are correct, as are the URLs. I get a cookie.txt file back with what looks like good data but I'm not sure.

If I try some basic debugging, like this:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://www.membersite.com/login.php");
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'username=deleted&password=deleted');
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'C:\xampp\htdocs\scrape\cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

if(!$store = curl_exec($ch))
{
    echo "login fail";
}

curl_setopt($ch, CURLOPT_URL, "http://www.membersite.com/memberlist.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

if(!$page = curl_exec($ch))
{
    echo "page fail";
}

echo $page;

curl_close($ch);

I get a "page fail" being printed to the page, so I guess the logging in isn't working.

Any help? thanks.

A: 

Nevermind, downloaded a phpBB cURL library and sorted it.

Matt
A: 

Add the CURLOPT_COOKIEFILE option with same value as the CURLOPT_COOKIEJAR option.

You also need to use those two options for each subsequent request (ie your request for memberlist.php).

You can see a way of doing it here.

cOle2