Jump to content

PriyaSingh

New Members
  • Content Count

    5
  • Joined

  • Last visited

Community Reputation

0 Neutral

About PriyaSingh

  • Rank
    Newbie
  1. i have been able to fetch data with an ajax call from active directory .The php file used to fetch data from active directory is below : <?php $username = 'maxxxxxxx'; $password = 'xxxxxxxxx'; $server = 'ldap://xxxxxxx'; $domain = '@asia.xxxxxx.com'; $port = 389; $ldap_connection = ldap_connect($server, $port); if (! $ldap_connection) { echo '<p>LDAP SERVER CONNECTION FAILED</p>'; exit; } // Help talking to AD ldap_set_option($ldap_connection, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($ldap_connection, LDAP_OPT_REFERRALS, 0); $ldap_bind = @ldap_bind($ldap_connection, $username.$domain, $password); if (! $ldap_bind) { echo '<p>LDAP BINDING FAILED</p>'; exit; } else { echo 'login successful'; } $base_dn = "OU=Employees,OU=Accounts,OU=India,DC=asia,DC=xxxxx,DC=com"; $dispname="Mark Hwett"; $filter ="(&(objectClass=user)(displayName=$dispname))"; $attr = array("sn","givenname","employeeid","distinguishedname","displayname","samaccountName","department","manager","mail","title","thumbnailphoto"); $result = ldap_search($ldap_connection,$base_dn,$filter,$attr); $rescount = ldap_count_entries($ldap_connection,$result); $data = ldap_get_entries($ldap_connection,$result); if ($data["count"] > 0) { for ($i=0; $i<$data["count"]; $i++) { echo "<p> sn: " . $data[$i]["sn"][0]."<br/>"; echo "givenname: ". $data[$i]["givenname"][0] ."<br/>" ; echo "employeeID: " . $data[$i]["employeeid"][0]."<br/>"; echo "distinguishedName: " . $data[$i]["distinguishedname"][0]."<br/>"; echo "displayName: " . $data[$i]["displayname"][0]."<br/>"; echo "sAMAccountName: " . $data[$i]["samaccountname"][0]."<br/>"; echo "department: ". $data[$i]["department"][0]."<br/>"; echo "manager: " .$data[$i]["manager"][0]."<br/>"; echo "mail: ". $data[$i]["mail"][0]."<br/>"; echo "title: " .$data[$i]["title"][0]."<br/>"; //echo "photo: " .$data[$i]["thumbnailphoto"][0]."<br/>"; // echo "<br/><br/>"; } } else { echo "<p>No results found!</p>"; } ?> The browser console shows that the above php returns this : <p> sn: xxxxxx<br/>givenname: xxxxx<br/> employeeID: 0050<br/ >distinguishedName: CN=xxxx xxxxx,OU=Employees,OU=Accounts,OU=India,DC=asia,DC=xxxxxxx,DC=com<br/> displayName: Mark Hewettk<br/>sAMAccountName: xxxxxxx<br/> department: xxxxx<br/>manager: CN=xxxxxx xxxxxxx,OU=Employees,OU=Accounts,OU=India,DC=asia,DC=xxxx,DC=com <br/> mail: mhewettk@abc.com<br/> title: xyz<br/> I want to take only some attributes from above data like mail,displayname etc and display in my HTML : <h2 class="profile__name" id="emailOfUser">Email : </h2> Now the problem is the jquery that I have used here : $('.leaderboard li').on('click', function () { $.ajax({ url: "../popupData/activedirectory.php", // your script above a little adjusted type: "POST", data: {id:$(this).find('.parent-div').data('name')}, success: function(data){ console.log(data); $('#popup').fadeIn(); $('#emailOfUser').html(data); //this line displays all data whereas I want to select only email,displayname from the above console data //whatever you want to fetch ...... // etc .. }, error: function(){ alert('failed, possible script does not exist'); } }); }); problem is this : $('#emailOfUser').html(data); this line displays all data whereas I want to select only email,displayname from the above console data kindly help me how to select only desired attribute data from the above browser console data i. the data returned by the ajax call.
  2. I understand some of the code in the JS is wrong.that is why I have come here.I have made the necessary changes as both of u suggest.Lets get to point here.U have any idea how to echo info from the above php file in an UI. If u know,kindly help.thanks.
  3. You misunderstood that.I am talking about how to pull the thumbnail photo.Whatever,you are saying I already did that.The console doesenot show anything .Even if it is able to pull the data from the active directory,fetching it in the UI is the issue.
  4. I have made an ajax call (using file activedirectory.php) to active directory to retrieve information such as name,thumbnail photo,mail etc. the ajax call is made on click of a name in a leaderboard ,to fetch only that person's info by matching the post['id']. The problem is that I am unable to retrieve any information and the console gives me an error saying : SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data the error type makes it clear that it is unable to pull any data whatsoever. .php file that has been used here :(activedirectory.php) -- <?php /** * Get a list of users from Active Directory. */ $ad_users = ''; $message = ''; $ldap_password = 'Qwerty@33xxxxxx'; $ldap_username = 'maxxxxxxxxxxxx'; $server = 'ldap://xxxxxxxxxx'; $domain = '@asia.xxxxxx.com'; $port = 389; $ldap_connection = ldap_connect($server, $port); if (FALSE === $ldap_connection){ // Uh-oh, something is wrong... } // We have to set this option for the version of Active Directory we are using. ldap_set_option($ldap_connection, LDAP_OPT_PROTOCOL_VERSION, 3) or die('Unable to set LDAP protocol version'); ldap_set_option($ldap_connection, LDAP_OPT_REFERRALS, 0); // We need this for doing an LDAP search. if (TRUE === ldap_bind($ldap_connection, $ldap_username.$domain, $ldap_password)){ $base_dn = "OU=Employees,OU=Accounts,OU=xxxxx,DC=xxxxx,DC=xxxxxx,DC=com"; $kid = 'NonExistingAccount'; if (preg_match('#SAM_NAME_MATCHING_REGEX#', $_POST['id'])) { $kid = $_POST['id']; } $search_filter = "(&(objectCategory=person)(samaccountname={$kid}))"; $attributes = array(); $attributes[] = 'givenname'; $attributes[] = 'mail'; $attributes[] = 'samaccountname'; $attributes[] = 'sn'; $result = ldap_search($ldap_connection, $base_dn, $search_filter, $attributes); $maxPageSize = 1000; if (FALSE !== $result){ $entries = ldap_get_entries($ldap_connection, $result); for ($x=0; $x<$entries['count']; $x++){ if (!empty($entries[$x]['givenname'][0]) && !empty($entries[$x]['mail'][0]) && !empty($entries[$x]['samaccountname'][0]) && !empty($entries[$x]['sn'][0]) && 'Shop' !== $entries[$x]['sn'][0] && 'Account' !== $entries[$x]['sn'][0]){ $ad_users[strtoupper(trim($entries[$x]['samaccountname'][0]))] = array('email' => strtolower(trim($entries[$x]['mail'][0])),'first_name' => trim($entries[$x]['givenname'][0]),'last_name' => trim($entries[$x]['sn'][0])); } } } ldap_unbind($ldap_connection); // Clean up after ourselves. } $message .= "Retrieved ". count($ad_users) ." Active Directory users\n"; ?> the javascript that has been used here : $('.leaderboard li').on('click', function () { $.ajax({ url: "../popupData/activedirectory.php", // your script above a little adjusted type: "POST", data: {id:$(this).find('.parent-div').data('id')}, success: function(data){ console.log(data); data = JSON.parse(data); $('#popup').fadeIn(); //whatever you want to fetch ...... // etc .. }, error: function(){ alert('failed, possible script does not exist'); } }); });
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.