[SOLVED] Login to phpBB forum using cURL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

[SOLVED] Login to phpBB forum using cURL

Post 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
Last edited by anjanesh on Sun Feb 26, 2006 11:07 am, edited 1 time in total.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

I assume they're not username and password. Make sure that the values got urlencoded.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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
Post Reply