IPB Integration + Pear

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

IPB Integration + Pear

Post 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;
    }
}
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply