Page 1 of 1

[SOLVED] Login to phpBB forum using cURL

Posted: Sat Feb 18, 2006 2:03 am
by anjanesh
Any idea how to login into a phpBB forum using cURL ?
I got redirected - but not with the username info on that page.

Code: Select all

<pre>
<?php
$u = "username";
$p = "password";

echo httpPOST_Curl("http://forums.devnetwork.net", "login.php", "username=$u&password=$p&autologin=on&login=Log%20in");

?>

<?
function httpPOST_Curl($Host, $Path, $Data)
 {
        $handle = curl_init();
        curl_setopt ($handle, CURLOPT_URL, $Host."/".$Path);
        curl_setopt ($handle, CURLOPT_POST, TRUE);
        curl_setopt ($handle, CURLOPT_POSTFIELDS, $Data);
        curl_setopt ($handle, CURLOPT_HEADER, TRUE);
        curl_setopt ($handle, CURLOPT_USERAGENT, "Mozilla/5.0");
        curl_setopt ($handle, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt ($handle, CURLOPT_REFERER, "localhost");
        curl_setopt ($handle, CURLOPT_CONNECTTIMEOUT, 1);
        $file_contents = curl_exec($handle);
        curl_close($handle);
        return $file_contents;
 }
?>
Thanks

Posted: Sat Feb 18, 2006 5:41 pm
by Ambush Commander
I assume they're not username and password. Make sure that the values got urlencoded.

Posted: Sat Feb 18, 2006 8:40 pm
by anjanesh
BTW, it works - sometimes it gets redirected though - dont know why.

I added 2 more lines

Code: Select all

curl_setopt ($handle, CURLOPT_COOKIEFILE, "cook.txt");
        curl_setopt ($handle, CURLOPT_COOKIEJAR,  "cook.txt");
But I dont see any cook.txt anywhere in my folder. phpBB stores some 4 cookies I believe. Where did they go ?

Thanks