What could I change in code to make it faster.
Code: Select all
Code updated & moved lowerModerator: General Moderators
Code: Select all
Code updated & moved lowerCode: Select all
<?php
class phpbb
{
var $curl=null;
// phpbb function
function phpbb($phpbb_url, $cookie_name = 'tmpfile.tmp')
{
if ( empty($phpbb_url) )
{
trigger_error('curl_phpbb::error, The phpBB location is required to continue, Please edit your script.');
return false;
}
$this->phpbb_url = $phpbb_url;
$this->cookie_name = $cookie_name;
}
// end phpbb function
// login function
function login($username, $password)
{
global $_SERVER;
$this->post_fields = $this->array_to_http(array(
'username' => $username,
'password' => $password,
'autologin' => 1,
'redirect' => 'index.php',
'login' => 'Log In',
));
$this->open("login.php", TRUE);
return TRUE;
}
// end login function
// page open function
function open($phpbb_page, $login)
{
global $_SERVER;
$this->curl = curl_init();
if($login==TRUE) {
curl_setopt ( $this->curl, CURLOPT_POST, true );
curl_setopt ( $this->curl, CURLOPT_POSTFIELDS, $this->post_fields );
} else {
curl_setopt ( $this->curl, CURLOPT_POST, false );
}
curl_setopt($this->curl, CURLOPT_URL, $this->phpbb_url.$phpbb_page);
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'] );
$result = curl_exec ( $this->curl );
curl_close($this->curl);
return $result;
}
// end - page open function
// array to http function
function array_to_http($array)
{
$retvar = '';
//foreach ($array as $field => $data)
while ( list ( $field, $data ) = @each ( $array ) )
{
$retvar .= ( empty($retvar) ) ? '' : '&';
$retvar .= urlencode($field) . '=' . urlencode($data);
}
return $retvar;
}
// and array to http function
}
$phpbb=new phpbb("http://www.example.org/");
$phpbb->login("example", "example");
echo $phpbb->open("index.php", FALSE);
?>