CURL and PHPBB



Hello there,

My need:

1. Log into PHPbb from a remote server.
2. View topics and forums via the remote server.
3. Post back to a specific topic or forum.
4. Log out.

What I have already done (thanks to a php class file):
1. Log into PHPbb from a remote server.
2. View topics and forums.

What I am having trouble with:
3. Posting and replying to topics from my remote server.

Here is my curl class (i didn't write this) for posting to phpbb:

///////// CODE /////////////
function new_topic($forum_id, $message, $topic_title)
{
global $_SERVER;

// Generate post string
$post_fields = $this->array_to_http(array(
'post' => 'Submit',
'mode' => 'post',
'message' => $message,
'f' => $forum_id,
'subject' => $topic_title,
'disable_bbcode' => 0,
'disable_smilies' => 0,
'attach_sig' => 1,
'topictype' => 0,
));
// Location
$url_vars = $this->array_to_http(array(
'mode' => 'post',
'f' => $forum_id,
));
// Init curl
$this->curl = curl_init();
// Set options
curl_setopt ( $this->curl, CURLOPT_URL, $this->phpbb_url .
'posting.php?' . $url_vars );
curl_setopt ( $this->curl, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt ( $this->curl, CURLOPT_POST, true );
curl_setopt ( $this->curl, CURLOPT_POSTFIELDS, $post_fields );
curl_setopt ( $this->curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $this->curl, CURLOPT_HEADER, false );
curl_setopt ( $this->curl, CURLOPT_COOKIE, $this->cookie_name );
curl_setopt ( $this->curl, CURLOPT_COOKIEJAR, $this->cookie_name );
curl_setopt ( $this->curl, CURLOPT_COOKIEFILE, $this->cookie_name );
curl_setopt ( $this->curl, CURLOPT_USERAGENT,
$_SERVER['HTTP_USER_AGENT'] );
// Execute request
$result = curl_exec ( $this->curl );
echo $result;
// Get the result
if ( preg_match ( '#<td align="center"><span class="gen">Your
message has been entered successfully.<br \/><br \/>#is', $result,
$match ) )
{
$post_status = 1;
}
else if ( preg_match ( '#<td align="center"><span class="gen">You
cannot make another post so soon after your last; please try again in
a short while.<\/span><\/td>>#is', $result, $match ) )
{
$post_status = 0;
}
else
{
$post_status = 0;
}
// Error handling
if ( curl_errno ( $this->curl ) )
{
$this->error = array(
curl_errno($this->curl),
curl_error($this->curl),
);
curl_close ( $this->curl );
return false;
}
// Close connection
curl_close ( $this->curl );
// Return result
return $post_status;
}
///////// END CODE ///////////

But, when I send my data to that function, and i echo $result, it says
'You need to be logged in.' But, i have already called the login
routine from my main script.

Here's the login call:

//////// CODE ///////////

// Log in
$phpbb->login('$funame', '$fpass');

//////// END CODE ///////

And, here is the curl login code:

////////// CODE ///////////
function login($username, $password)
{
global $_SERVER;

// Generate post string
$post_fields = $this->array_to_http(array(
'username' => $username,
'password' => $password,
'autologin' => 0,
'redirect' => 'index.php',
'login' => 'Log In',
));
// Init curl
$this->curl = curl_init();
// Set options
curl_setopt ( $this->curl, CURLOPT_URL, $this->phpbb_url . 'ucp.php?
mode=login' );
curl_setopt ( $this->curl, CURLOPT_POST, true );
curl_setopt ( $this->curl, CURLOPT_POSTFIELDS, $post_fields );
curl_setopt ( $this->curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $this->curl, CURLOPT_HEADER, false );
curl_setopt ( $this->curl, CURLOPT_COOKIE, $this->cookie_name );
curl_setopt ( $this->curl, CURLOPT_COOKIEJAR, $this->cookie_name );
curl_setopt ( $this->curl, CURLOPT_COOKIEFILE, $this->cookie_name );
curl_setopt ( $this->curl, CURLOPT_USERAGENT,
$_SERVER['HTTP_USER_AGENT'] );
// Execute request
$result = curl_exec ( $this->curl );
// Error handling
if ( curl_errno ( $this->curl ) )
{
$this->error = array(
curl_errno($this->curl),
curl_error($this->curl),
);
curl_close ( $this->curl );
return false;
}
// Close connection
curl_close ( $this->curl );
// Return result
return true;
}
///////// END CODE ///////////

I think the problem is simply that the class for curl doesn't pull the
session id from the phpbb forum after logging in and pass the session
id with the url variable's when creating the post. I could be wrong,
don't know.

Anyone have any ideas on how to fix/accomplish this? I've been
searching for days without much luck.

I can include the entire class file, if you wish.

Thanks!
.



Relevant Pages

  • Re: A couple new jazz pieces finished
    ... forums. ... As soon as we started the phpBB up again the activity ... so Why did you come here with your original post - I noatice from ... source is 24 (some tracks 0 plays). ...
    (rec.music.makers.songwriting)
  • Re: phpbb for lists.debian.org
    ... > Could lists.debian.org be served with phpbb instead of email lists? ... > And two, phpbb is much better for archiving, searching, etc. See ... > mozilla forums, OOo forums, etc, etc, etc. ...
    (Debian-User)
  • Re: Slightly OT; Opinions on Forum type software
    ... I participate on several sites that use phpbb with mysql. ... Does your host charge monthly for MySQL (which is _not_ the same as MS SQL ... Host supports PHPBB and Snitz type forums (and will install them for small ... I like the look of php better than snitz, but I suppose the can both be ...
    (microsoft.public.frontpage.client)
  • Re: how to get free discussion on my website ?
    ... http://support.forumgogo.com More powerful than the phpbb ... I looked at a dozen forums and they all looked ... as I hear it the RPG was only a genre because of the limitations ...
    (comp.sys.ibm.pc.games.rpg)
  • publishing in FP 2003
    ... >We have a website on a remote server, ... >installed a public forum using phpbb. ...
    (microsoft.public.frontpage.programming)

Loading