Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2005
    Messaggi
    12

    Ricerca autocomplete jquey su Active Directory Windows

    Buongiorno a tutti
    premesso che non sono un esperto, sto cercando di fare una ricerca per user o nome su AD.
    Ho trovato degli esempi e ho implementato due pagine:
    - test_ad.php
    - leggi.php

    Non riesco a passare variabili (credo) e la ricerca rilascia tutti i nominativi ma non ricerca per nome.
    Potete aiutarmi? Grazie in anticipo.

    test_ad.php
    Codice PHP:
    <!DOCTYPE html>
    <
    html>
          <
    head>
              <
    title>Autocomplete textbox using jQueryPHP and LDAP</title>
              <
    link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"; />
              <
    script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>;
              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>;
              <style>
              ul{
                    background-color:#eee;
                    cursor:pointer;
              }
              li{
                    padding:12px;
              }
              </style>
          </head>
          <body>
              <br /><br />
              <div class="container" style="width:500px;" action="test_ad.php" method="POST">
                    <h3 align="center">Autocomplete textbox using jQuery, PHP and LDAP</h3><br />
                    <label>Enter Name</label>
                    <input type="text" name="search-box" id="search-box" class="form-control" placeholder="Enter Name" />
                    <div id="suggesstion-box"></div>
              </div>
          </body>
    </html>
    <script>
    $(document).ready(function(){
          $('#search-box').keyup(function(){
              //var query = $('#search-box').val();
              var query = $('#search-box').val();
              if(query != '')
              {
                    $.ajax({
                        url:"leggi.php",
                        method:"REQUEST",
                        data:{query:query},
                        success:function(data)
                        {
                              $('#suggesstion-box').fadeIn();
                              $('#suggesstion-box').html(data);
                        }
                    });
              }
          });
          $(document).on('click', 'li', function(){
              $('#search-box').val($(this).text());
              $('#suggesstion-box').fadeOut();
          minLength: 3
          });
    });
    </script> 

    leggi.php

    Codice PHP:
    <!DOCTYPE html>
    <
    html>
          <
    head>
              <
    title>Autocomplete textbox using jQueryPHP and LDAP</title>
              <
    link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"; />
              <
    script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>;
              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>;
              <style>
              ul{
                    background-color:#eee;
                    cursor:pointer;
              }
              li{
                    padding:12px;
              }
              </style>
          </head>
          <body>
              <br /><br />
              <div class="container" style="width:500px;" action="test_ad.php" method="POST">
                    <h3 align="center">Autocomplete textbox using jQuery, PHP and LDAP</h3><br />
                    <label>Enter Name</label>
                    <input type="text" name="search-box" id="search-box" class="form-control" placeholder="Enter Name" />
                    <div id="suggesstion-box"></div>
              </div>
          </body>
    </html>
    <script>
    $(document).ready(function(){
          $('#search-box').keyup(function(){
              //var query = $('#search-box').val();
              var query = $('#search-box').val();
              if(query != '')
              {
                    $.ajax({
                        url:"leggi.php",
                        method:"REQUEST",
                        data:{query:query},
                        success:function(data)
                        {
                              $('#suggesstion-box').fadeIn();
                              $('#suggesstion-box').html(data);
                        }
                    });
              }
          });
          $(document).on('click', 'li', function(){
              $('#search-box').val($(this).text());
              $('#suggesstion-box').fadeOut();
          minLength: 3
          });
    });
    </script> 

  2. #2
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,505
    I codici di queste due pagine sono tutti in JS e HTML, perché chiedi nella sezione PHP?

  3. #3
    Utente di HTML.it
    Registrato dal
    Apr 2005
    Messaggi
    12
    Ciao Buongiorno,
    scusami pensavo che i file essendo in php andassero postati in questa sezione.
    il file leggi.php ha codice php. Adesso ho notato che ho sbagliato a inserire il codice!
    Come faccio a correggere/spostare il post?
    grazie
    Ultima modifica di Linnox; 24-10-2019 a 11:44

  4. #4
    Utente di HTML.it
    Registrato dal
    Apr 2005
    Messaggi
    12

    errata corrige codice esatto

    La pagina leggi.php funziona se nella url passo la variabile, come posso inviare la variabile dalla pagina con il form di ricerca (test_ad.php)? Non riesco a capire.
    grazie


    Quote Originariamente inviata da Linnox Visualizza il messaggio
    Buongiorno a tutti
    premesso che non sono un esperto, sto cercando di fare una ricerca per user o nome su AD.
    Ho trovato degli esempi e ho implementato due pagine:
    - test_ad.php
    - leggi.php

    Non riesco a passare variabili (credo) e la ricerca rilascia tutti i nominativi ma non ricerca per nome.
    Potete aiutarmi? Grazie in anticipo.

    test_ad.php
    Codice PHP:
    <!DOCTYPE html>
    <
    html>
          <
    head>
              <
    title>Autocomplete textbox using jQueryPHP and LDAP</title>
              <
    link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"; />
              <
    script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>;
              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>;
              <style>
              ul{
                    background-color:#eee;
                    cursor:pointer;
              }
              li{
                    padding:12px;
              }
              </style>
          </head>
          <body>
              <br /><br />
              <div class="container" style="width:500px;" action="test_ad.php" method="POST">
                    <h3 align="center">Autocomplete textbox using jQuery, PHP and LDAP</h3><br />
                    <label>Enter Name</label>
                    <input type="text" name="search-box" id="search-box" class="form-control" placeholder="Enter Name" />
                    <div id="suggesstion-box"></div>
              </div>
          </body>
    </html>
    <script>
    $(document).ready(function(){
          $('#search-box').keyup(function(){
              //var query = $('#search-box').val();
              var query = $('#search-box').val();
              if(query != '')
              {
                    $.ajax({
                        url:"leggi.php",
                        method:"REQUEST",
                        data:{query:query},
                        success:function(data)
                        {
                              $('#suggesstion-box').fadeIn();
                              $('#suggesstion-box').html(data);
                        }
                    });
              }
          });
          $(document).on('click', 'li', function(){
              $('#search-box').val($(this).text());
              $('#suggesstion-box').fadeOut();
          minLength: 3
          });
    });
    </script> 

    leggi.php

    Codice PHP:
    set_time_limit(30);
    error_reporting(E_ALL);
    ini_set('error_reporting'E_ALL);
    ini_set('display_errors',1);
    $key $_REQUEST['search-box'];
    ///echo "".$key."<br>";
    // config
    $ldapserver 'local';
    $ldapuser   'use';
    $ldappass   'password';
    $ldaptree   "OU=xx,DC=xxx,DC=xxx";

    // connect
    $ldapconn ldap_connect($ldapserver) or die("Could not connect to LDAP server.");
    ldap_set_option($ldapconnLDAP_OPT_PROTOCOL_VERSION3);
    ldap_set_option($ldapconnLDAP_OPT_REFERRALS0);
    if(
    $ldapconn) {
        

        
        
    // binding to ldap server
        
    $ldapbind ldap_bind($ldapconn$ldapuser$ldappass) or die ("Error trying to bind: ".ldap_error($ldapconn));
        
    // verify binding
        
    if ($ldapbind) {
            echo 
    "LDAP bind successful...<br /><br />";
       
        
    $search_filter '(&(objectCategory=person)(objectClass=user)(sn=*'$key .'*))';
        
    $attributes = array();
        
    $attributes[] = 'cn';
        
    $attributes[] = 'mail';
        
    $attributes[] = 'samaccountname';
        
    $attributes[] = 'sn';
        
    $result ldap_search($ldapconn,$ldaptree,$search_filter,$attributes) or die ("Error in search query: ".ldap_error($ldapconn));
        
    ldap_sort($ldapconn,$result,"sn");
        
    $data ldap_get_entries($ldapconn$result);
           

            
    // iterate over array and print data for each entry
            
    echo '<h1>Utenti</h1>';
            
            for (
    $i=0$i<$data["count"]; $i++) {
                
    //echo "dn is: ". $data[$i]["dn"] ."<br />";
                
    echo "User: "$data[$i]["cn"][0] ."<br />";
                if(isset(
    $data[$i]["mail"][0])) {
                    echo 
    "Email: "$data[$i]["mail"][0] ."<br /><br />";
                } else {
                    echo 
    "Email: None<br /><br />";
                }
            }
            echo 
    "".$key."<br>";
            
    // print number of entries found
            
    echo "Number of entries found: " ldap_count_entries($ldapconn$result);
        } else {
            echo 
    "LDAP bind failed...";
        }
    }

    // all done? clean up
    ldap_close($ldapconn); 

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.