You are here: CURL and PHPBB « PHP Programming Language « IT news, forums, messages
CURL and PHPBB

Posted by zackrspv on 01/31/08 00:54

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!

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация