djollie029 Posted April 11, 2015 Share Posted April 11, 2015 Hi all, I have been trying to find the answer to this for the past 3 days by searching many forums and am resorting to asking the question myself now as I'm totally stuck! Quite simply I need to do the following for a new Staff Intranet I'm building that uses Windows Authentication in IIS... I am a system administrator and so have full access to our Active Directory on Server 2012. I need a simple PHP script that takes the username of the current logged on user $_SERVER["AUTH_USER"] and connects to our local Active Directory (LDAP) for which I can provide administrator credentials for (so it does not need to be an anonymous connection). I then need the script to look up the user based on the Auth_User result above for the user looking at the Intranet Site, and return the DisplayName and Email Address for that user and store them in a session to be used elsewhere on the Intranet Site. In theory I imagine this is quite simple, however I have struggled to get other scripts working to what I need. Any help would be really appreciated!! Thank you :-) Quote Link to comment https://forums.phpfreaks.com/topic/295446-php-active-directory-get-displayname-field-for-current-user/ Share on other sites More sharing options...
djollie029 Posted April 13, 2015 Author Share Posted April 13, 2015 Any help would be really appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/295446-php-active-directory-get-displayname-field-for-current-user/#findComment-1508922 Share on other sites More sharing options...
gizmola Posted April 13, 2015 Share Posted April 13, 2015 People are here to help, but not write scripts on demand. As you have indicated, you already understand that AD is LDAP compliant, so you need to make sure you have enabled LDAP support. The details and options for his depend on the OS of your webserver running PHP. If you have code, and specific issues, you should post them here, but until people have something to help you with, I'm not sure what anyone can do for you. Quote Link to comment https://forums.phpfreaks.com/topic/295446-php-active-directory-get-displayname-field-for-current-user/#findComment-1508932 Share on other sites More sharing options...
Barand Posted April 13, 2015 Share Posted April 13, 2015 I found the ADLDAP class a great help when working on intranets with active directory https://github.com/adldap/adLDAP 1 Quote Link to comment https://forums.phpfreaks.com/topic/295446-php-active-directory-get-displayname-field-for-current-user/#findComment-1508933 Share on other sites More sharing options...
djollie029 Posted April 13, 2015 Author Share Posted April 13, 2015 Thanks @Barand for your help. I have also been playing around with adLDAP for a couple of days but cannot quite get the SSO element to work. In the adLDAP I have set useSSO variable to True.I have then tried multiple ways to call that file and authenticate a user with no luck. Below I have posted the cutdown code I am trying to test with. What am I doing wrong please?php_ldap.dll is enabled in the PHP ini file. Thanks in advance! <?phprequire_once(dirname(FILE) . '/../src/adLDAP.php');$adldap = new adLDAP();$adldap->user($username, $password);$result=$adldap->user()->infoCollection("username", array("*"));echo $result->displayName;echo $result->mail;?> Quote Link to comment https://forums.phpfreaks.com/topic/295446-php-active-directory-get-displayname-field-for-current-user/#findComment-1508961 Share on other sites More sharing options...
Solution djollie029 Posted April 14, 2015 Author Solution Share Posted April 14, 2015 I've finally managed to get what I need working with the adLDAP and SSO. For future reference for anyone else looking for similar solution to get the firstname and lastname from Active Directory that matches the logged on users username... <?php session_start(); $username = explode('\\',$_SERVER["LOGON_USER"]); $_SESSION['username'] = strtolower($username[1]); ?> <?php include ("/../src/adLDAP.php"); $ldap=new adLDAP(); $userinfo = $ldap->user()->info($_SESSION['username'],array("givenname","sn")); $_SESSION['firstname'] = $userinfo[0][givenname][0]; $_SESSION['lastname'] = $userinfo[0][sn][0]; $firstname = $_SESSION['firstname']; $lastname = $_SESSION['lastname']; ?> <br /> <strong>Welcome </strong><?php printf("<b><i>$firstname $lastname</i></b>"); ?> 1 Quote Link to comment https://forums.phpfreaks.com/topic/295446-php-active-directory-get-displayname-field-for-current-user/#findComment-1508988 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.