Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Senior Member tha_Gsheep's Avatar
    Join Date
    Feb 2003
    Location
    Scotland
    Posts
    188
    Member #
    780
    Could someone help me figure out a problem with getting PEAR::auth to run in a manager class. I've tried for hours to search for existing examples but I can find nought.
    I know its already a class but I want to wrap it in a management class so I don't have to keep clogging up pages with invoking the auth() object at the start of the page. I've worked with the examples and they work fine, if I wanted to include the code on every login page but I want to further 'abstract' it
    heres the class that invokes it:
    PHP Code:
    <?php

    require_once("PEAR.php");
    require_once(
    "DB.php");
    require_once(
    "Auth.php");
    require_once(
    "../includes/classes/class_AuthMgr.php");

    $AuthMgr = new AuthMgr();



     if (
    $AuthMgr->isLoggedIn())
    {
        
    // Do this
    }
    else
    {
        
    // Not authenticated
    }

    ?>

    and heres the AuthMgr class:
    PHP Code:
    <?php

    class AuthMgr{

        var 
    $params         = array();


    function 
    AuthMgr(){


        
    $this->params = array(
                      
    "dsn" => "mysql://user:pass@localhost/dbname",  //These are just substiutes
                      
    "table" => "auth",
                      
    "usernamecol" => "username",
                      
    "passwordcol" => "password"
                  
    );
        
    $this->startSession();
        
    }

    function 
    startSession(){

        
    $this->Auth = &new Auth("DB"$params$this->loginFunction() );
        
    $this->Auth->start();

    }

    function 
    isLoggedIn(){
        switch(
    $this->Auth->getAuth()){
            case 
    TRUE: return TRUE;
            case 
    FALSE: return FALSE;
        }
    }

    function 
    loginFunction()
    {
        echo 
    "<form method=\"post\" href= \"".$_SERVER['PHP_SELF']."?act=login\">";
        echo 
    "<input type=\"text\" name=\"username\">";
        echo 
    "<input type=\"password\" name=\"password\">";
        echo 
    "<input type=\"submit\">";
        echo 
    "</form>";
    }

    }
    ?>
    The code generates the page fine but just does not ever seem to log in. I know that I should actually be passing a callback to a function rather than the result of the function int the auth(DB, params, "login") but that just plain does'nt work either. Can anyone see any glaring errors in the way I am objectifying it?
    www.appletv.co.uk

  2.  

  3. #2
    Senior Member tha_Gsheep's Avatar
    Join Date
    Feb 2003
    Location
    Scotland
    Posts
    188
    Member #
    780
    Silly me. I was trying to make an object where there need not be one. All I needed to do was include the actual php file at the top of my page. The I would initialise the auth object from within the auth constructor of the included php file.

    PHP Code:
    <?php

        $params 
    = array(
                      
    "dsn" "dsn" => "mysql://user:pass@localhost/dbname",  //These are just substiutes  
                      
    "table" => "auth",
                      
    "usernamecol" => "username",
                      
    "passwordcol" => "password"
                  
    );

        
    // A database is used as storage container in this example
        
    $Auth = &new Auth("DB"$params"loginFunction"); //Take out the "loginFunction" to toggle the default signin
        
        // Detection, if user is logged in. Otherwise the login form
        // is being displayed.
        
    $Auth->start();
    }

    function 
    loginFunction()
    {
        echo 
    "<form method=\"post\" href= \"".$_SERVER['PHP_SELF']."?act=login\">";
        echo 
    "<input type=\"text\" name=\"username\">";
        echo 
    "<input type=\"password\" name=\"password\">";
        echo 
    "<input type=\"submit\">";
        echo 
    "</form>";

        
    }
    ?>
    So Just to be clear for anyone who may stumble upon this in future. To further call functions from within the included Auth file, lets say for instance you wanted to check if they were logged in, you would do this:

    PHP Code:
    <?php
    require_once("PEAR.php");
    require_once(
    "DB.php");
    require_once(
    "Auth.php");
    require_once(
    "../includes/classes/class_AuthMgr.php");


        if(
    $Auth->getAuth()){
            echo 
    "Still logged in";
        }else
        {
            echo
    "logged out";
        }
    ?>
    www.appletv.co.uk


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 06:03 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com