#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    2
    Rep Power
    0

    Help with code not working


    Hope someone can help me with this. Here is what I am trying to do... I am using a wordpress plugin that authenticates to Active Directory, however when the user logs in I need to php page to check for the group the user belongs to and if they are part of a particular group they will have certain access on the site. Here is the part of the code that I am using which does not seem to work, when they login it does not detect the group that they are in...

    $str = shell_exec('./grouptestfull.php -u'.$LoggedInUsername);

    calls grouptestfull.php which is this...

    PHP Code:

    #!/usr/bin/php -q
    <?php
    /*
    Version 1 - inital version
    */

    error_reporting(0);

    $arguments getopt("u:");
    //print_r($arguments);

    print $arguments['u'];
    //print grouptestfull($loggedinusersusername);

    echo grouptestfull($arguments['u']);

    function 
    grouptestfull($gtfusernamein)
    {
        
    // clear the flags
        
    $validhr false;
        
    $validinf false;
        
    $validroot false;

        
    //print "username as receved by function ".$gtfusernamein."<br>";
        
    $gtfusername ""
        
    $gtfusername $gtfusernamein."";

        
    //print "processed username ".$gtfusername."<br><hr>";
        
    include("adLDAP.php");
        try
        {
         
    $gtfadldapedit = new adLDAP();
        }
        catch (
    adLDAPException $e
        {
         echo 
    $e; exit();
        }

        
    //check group membership
        
    if(($gtfadldapedit->user_ingroup($gtfusername."","SD.HR")))
        {
            
    $validhr true;
        }

        if((
    $gtfadldapedit->user_ingroup($gtfusername."","SD.INF")))
        {
            
    $validinf true;
        }
        
        if((
    $gtfadldapedit->user_ingroup($gtfusername."","SD.ROOT")))
        {
            
    $validroot true;
        }
        
        
    //sort and return highest lvl group membership
        
    if ($validroot)
        {
            return 
    "validroot";
        }
        else
        {
            if (
    $validinf)
            {
                return 
    "validinf";
            }    
            if (
    $validhr)
            {
                return 
    "validhr";
            }
            else
            {
                
    //return "";
            
    }
        }
    }     
    ?>
    I get no errors in the php error log, but just can't figure out why this is not working.

    Thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,232
    Rep Power
    593
    Please edit your post and enclose your code in PHP tags. See ManiacDan's New User Guide for details and many good tips on debugging your own code. That having been said, I suggest you try using PHP's builtin LDAP API.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo