gavinr98 Posted March 28, 2012 Share Posted March 28, 2012 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 the 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... #!/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 Quote Link to comment Share on other sites More sharing options...
NomadicJosh Posted March 30, 2012 Share Posted March 30, 2012 This doesn't seem right, but I have to ask questions to be sure: //print "username as receved by function ".$gtfusernamein."<br>"; $gtfusername = ""; $gtfusername = $gtfusernamein.""; Why not just do this instead and what is the point of the "" at the end? $gtfusername = $gtfusernamein; Also, just to be sure, from reading your print text, I don't understand if you are saying this is a function ($gtfusernamein) or it is just a statement. Because the way you have $gtfusernamein now, it is a variable. If it is to be a function, then it should be this instead gtfusernamein(). Quote Link to comment Share on other sites More sharing options...
gavinr98 Posted April 10, 2012 Author Share Posted April 10, 2012 Thanks for the reply, I tried that and still does not seem to work. The code was given to me by someone so not sure why it was done this way. Any suggestions on making this work would be great. Quote Link to comment Share on other sites More sharing options...
jac.kock Posted April 25, 2012 Share Posted April 25, 2012 Thanks for the reply, I tried that and still does not seem to work. The code was given to me by someone so not sure why it was done this way. Any suggestions on making this work would be great. mabey when you set repto_error(0); to 1 mabey it will show youre error? Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 25, 2012 Share Posted April 25, 2012 you need to turn error reporting on. | | V Quote Link to comment Share on other sites More sharing options...
gavinr98 Posted May 8, 2012 Author Share Posted May 8, 2012 I turned on error reporting and don't get any errors. I was able to add some additional tests to the script and when doing so it always returns "null" and does not determine what group the users is in. Here is the new code I am using... any help would be appreciated. <?php ini_set('display_errors', 1); error_reporting (E_ALL); $arguments = getopt("u"); echo grouptestfull($arguments['u']); function grouptestfull($user) { require_once(dirname(__FILE__) . '/adLDAP.php'); $adldap = new adLDAP(); try { $ldap_db = new adLDAP(); } catch (adLDAPException $e) { echo $e; exit(); } // clear the flags $validhr = false; $validinf = false; $validroot = false; //check group if(($ldap_db->user_ingroup($user,"SD.HR", true))) { echo "\nvalidhr\n"; $validhr = true; } if(($ldap_db->user_ingroup($user,"SD.INF", true))) { echo "\nvalidinf\n"; $validinf = true; } if(($ldap_db->user_ingroup($user,"SD.ROOT", true))) { echo "\nvalidroot\n"; $validroot = true; } //sort and return highest lvl group membership if ($validroot) { return "validroot"; echo "validroot"; //for testing only } else { echo "GOT HERE1"; //for testing only if ($validinf) { return "validinf"; echo "validinf"; //for testing only } else { if ($validhr) { ; return "validhr"; echo "Validhr"; //for testing only } else { echo "null"; //for testing only return ""; } } } } echo "GOT HERE2"; //for testing only ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.