Page 1 of 1

IPB Integration + Pear

Posted: Sat Mar 03, 2007 1:31 pm
by thiscatis
Hi,
I trying a tutorial to integrate Invision Power Board member groups with my site.

I found this great tutorial:
http://lotsofphp.com/tutorials/creating ... class.html

But I'm not familiar with PEAR::DB so I'm confused what to put here:

Code: Select all

<?php
class members
{
    var $db = "";
...
Because the class is init by

Code: Select all

$members = new members();
$members->db =& $db // assume PEAR::DB is stored in this variable
$members->check_cookie();

Full class:

Code: Select all

<?php
class members
{
    var $db = "";
    var $current = array();
    
    function check_cookie()
    {
        if( isset( $_COOKIE['member_id'] ) && isset( $_COOKIE['pass_hash'] ) )
        {
            $_COOKIE['member_id'] = intval( $_COOKIE['member_id'] );
            if( $this->db->getOne( "SELECT * FROM gcpibf_members WHERE id={$_COOKIE['member_id']}
                AND member_login_key='{$_COOKIE['pass_hash']}'" ) != 0 )
            {
                $result = $this->db->query( "SELECT * FROM gcpibf_members WHERE id={$_COOKIE['member_id']} LIMIT 1" );
                if( DB::isError( $result ) )
                {
                    die( mysql_error() );
                }
                
                $this->current = $result->fetchrow( DB_FETCHMODE_ASSOC );
            }
            else
            {
                $this->identify_guest();
            }
        }
        else
        {
            $this->identify_guest();
        }
    }
    
    function identify_guest()
    {
        $this->current = array( 'name' => 'Guest', 'mgroup' => 0 );
    }
    
    function is_loggedin()
    {
        if( isset( $this->current ) )
        {
            if( $this->current['mgroup'] != 0 )
            {
                return true;
            }
        }
    }
    
    function is_admin()
    {
        if( $this->is_loggedin() )
        {
            if( $this->current['mgroup'] == 4 )
            {
                return true;
            }
        }
    }
    
    function get_info()
    {
        return $this->current;
    }
}
?>

Posted: Sat Mar 03, 2007 1:39 pm
by feyd
You don't directly write anything into the class definition.

http://pear.php.net/manual/en/package.d ... onnect.php has an example that may help.