Witam na forum smile.gif
Próbuję zrobić automatyczne logowanie z mojej strony na forum. Z phpBB i vBulletin dałem sobie radę, ale mam problem z Invision Power Board. Mam taki skrypt:
index.php:
<?php
// Init class
include('curl_phpbb.class.php');
include('curl_vbull.class.php');
include('curl_ipb.class.php');
// The ending backslash is required.
$ipb = new curl_ipb('urlforum');
// Log in
$ipb->login('logindoforum', 'hasło');
// Read index
echo $ipb->read('index.php');
?>
curl_ipb.class.php:
<?php
class curl_ipb
{
var $curl = null;
var $cookie_name = array(); var $ipb_url = null;
function curl_ipb($ipb_url, $cookie_name = 'tmpfile.tmp')
{
// Check CURL is present
if ( ! function_exists ( 'curl_init') )
{
// Output an error message
trigger_error('curl_ipb::error, Sorry but it appears that CURL is not loaded, Please install it
to continue.'); return false;
}
{
// Output an error message
trigger_error('curl_ipb::error, The ipb location is required to continue, Please edit your scri
pt.'); return false;
}
// Set base location
$this->ipb_url = $ipb_url;
// Create temp file
$this->cookie_name = $cookie_name;
}
/*
@ Function : login() - Log In
@ About : Does a remote login to the target ipb and stores in cookie
@ Type : Public
*/
function login($username, $password)
{
// Generate post string
$post_fields = $this->array_to_http(array( 'referer' => $this->ipb_url,
'CookieDate' => 1,
'UserName' => $username,
'PassWord' => $password,
));
// Init curl
$this->curl = curl_init();
// Set options
curl_setopt ( $this->curl, CURLOPT_URL, $this->ipb_url . 'index.php?act=login&CODE=00' );
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 ) )
{
curl_errno($this->curl),
curl_error($this->curl),
);
curl_close ( $this->curl );
return false;
}
// Close connection
curl_close ( $this->curl );
// Return result
return true;
}
/*
@ Function : read() - Read a pages contents
@ About : Returns the contents of a url
@ Type : Public
*/
function read($page_url)
{
// Init curl
$this->curl = curl_init();
// Set options
curl_setopt ( $this->curl, CURLOPT_URL, $this->ipb_url . $page_url );
curl_setopt ( $this->curl, CURLOPT_POST, false );
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 ) )
{
curl_errno($this->curl),
curl_error($this->curl),
);
curl_close ( $this->curl );
return false;
}
// Close connection
curl_close ( $this->curl );
// Return result
return $result;
}
...kolejne funkcje, nieważne bo nie są używane do logowania
?>
Używając skryptu do logowania na vB i phpBB zmieniałem nazwy i zawartość $post_fields. Z iPB próbowałem z różnymi kombinacjami, ale nic to nie dało. Po otworzeniu index.php otrzymuję białą, pustą stronę.
Ten post edytował emerge. 11.08.2008, 09:43:58