Probleme php et active directory

Bonjour,
je veu faire la liaison entre 3 pages:
la premiere page permet de s'authentifier
la deuxieme permet de rechercher le Username qui a été entré si il est connectée sur le domaine de l'active directory ou non si oui la 3éme page permet toutes les informations sur ce Username

Configuration: Windows / Edge 85.0.564.44

6 réponses

  1. j'ai maitrisée le php , le html et le css mais j'ai un probléme de faire une interface par ces 3 langages ensemble et merci tu m'aides jamais ,tu es resté juste de me poser des questions . si tu veux m'aider merci d'avance sinon ton mieux
    1. je veux faire une liaison entre la page 2 et 3
      je veux que la page 3 affiche les informations sur le USER qui a entré dans la page 2
      1. Contributeur
        est-ce le premier site que tu fais en php? as-tu suivi une formation en php?
        j'ai l'impression que tu ne maîtrises pas encore les principes de base, et que tu nous demandes de faire ce travail à ta place.
    2. tu es lu mon probleme??
      1. Contributeur
        j'ai lu ce que tu as écrit, et je n'ai rien compris.
    3. page1:
      <?php
      //Affichage erreurs php
      error_reporting(E_ALL);
      ini_set('display_errors', TRUE);
      ini_set('display_startup_errors', TRUE);
      
      // Constantes et autres variables
      define('USER','Stage');
      define('PASSWORD','Stage2020');
      $message='';
      $url_page2 = "page2.php"; // variable à modifier selon tes besoins
      
      // récupération propre des variables (POST/GET/SESSION...) AVANT de les utiliser
      $user = !empty($_POST['user']) ? trim($_POST['user']) : NULL;
      $password = !empty($_POST['password']) ? trim($_POST['password']) : NULL;
      
        //traitement du submit
      if(isset($_POST['submit'])){
        if(!$user  || !$password){
          $message='veuillez indiquer vos identifiants !';
        }elseif($user != USER || $password != PASSWORD ){
          $message='Vos identifiants sont faux. Merci de les vérifier';
        }elseif($user == USER || $password = PASSWORD){
           // tout est ok... donc :
           header('location:'.$url_page2);
           exit; // toujours mettre un exit après une redirection
        }
      }
      
      ?>
      <!DOCTYPE html>
      <html lang="fr">
        <head>
          <meta charset="utf-8">
          <meta name="viewport" content="width=device-width, initial-scale=1">
          <style>
          * {
            box-sizing: border-box;
          }
      
          body {
            margin: 0;
          }
      
          /* Style the header */
          .header {
            background-color:white;
            padding: 50px;
            text-align: center;
          }
      
          /* Style the top navigation bar */
          .topnav {
            overflow: hidden;
            background-color: white;
          }
          /* Create three unequal columns that floats next to each other */
          .column {
            float: left;
            padding: 70px;
          }
      
          /* Left and right column */
          .column.side {
            width: 25%;
            
          }
      
          /* Middle column */
          .column.middle {
            width: 50%;
            background-color:rgb(0, 100, 255);
          }
      
          /* Clear floats after the columns */
          .row:after {
            content: "";
            display: table;
            clear: both;
          }
          /* Style the footer */
          .footer {
            background-color: white;
            padding: 40px;
            text-align: center;
          }
      
          /* Responsive layout - makes the three columns stack on top of each other instead of next to each other */
          @media screen and (max-width: 600px) {
            .column.side, .column.middle {
              width: 100%;
            }
          }
          
          #btn_submit{
            padding-left:60px;
          }
          
          #div_error{
            margin-left:80px;
          }
          
          </style>
        </head>
        <body>
          <div class="header">
           
          </div>
          <div class="topnav">
            
          </div>
          <div class="row">
            <div class="column side">
          </div>
          <div class="column middle">
            <center>
            <h1 style="border:3px solid #ff6347;">welcome</h1>
            <br>
            <form action="" method="post">
              <strong><im><h3>
              <label for="username" >Username: </label>
              <input id="user" type="text" name="user" Size="20" value="<?php echo htmlspecialchars($user);?>"/> 
              <br><br>
              <label for="password" >Password: </label>
              <input id="user" type="text" name="password" Size="20" value="<?php echo htmlspecialchars($password);?>"/>
              <br><br>
              <input type="submit" id="btn_submit" name="submit" value="Submit" />
            </form>
      
            <?php 
            if(!empty($message)){
              echo '<div id="div_error">';
              echo '<p style="color:red;">'.$message.'</p>';
              echo '</div>';
            }
            ?>
          </div>
          <div class="column side">
             
          </div>
          <div class="footer">
           
          </div>
        </div>
      
        </body>
      </html>
      1. page2:
        <html lang="en">
        <head>
        
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <style>
        * {
          box-sizing: border-box;
        }
        
        body {
          margin: 0;
        }
        
        /* Style the header */
        .header {
          background-color:white;
          padding: 50px;
          text-align: center;
        }
        
        /* Style the top navigation bar */
        .topnav {
          overflow: hidden;
          background-color: white;
        }
        
        
        
        
        
        /* Create three unequal columns that floats next to each other */
        .column {
          float: left;
          padding: 70px;
        }
        
        /* Left and right column */
        .column.side {
          width: 25%;
          
        }
        
        /* Middle column */
        .column.middle {
          width: 50%;
          background-color:rgb(0, 100, 255);
        }
        
        /* Clear floats after the columns */
        .row:after {
          content: "";
          display: table;
          clear: both;
        }
        /* Style the footer */
        .footer {
          background-color: white;
          padding: 40px;
          text-align: center;
        }
        
        /* Responsive layout - makes the three columns stack on top of each other instead of next to each other */
        @media screen and (max-width: 600px) {
          .column.side, .column.middle {
            width: 100%;
          }
        }
        </style>
        </head>
        <body>
        
        <div class="header">
         
        </div>
        
        <div class="topnav">
          
        </div>
        
        <div class="row">
          <div class="column side">
           
          </div>
          
          <div class="column middle">
          <center>
         <br>
          <form action="" method="POST">
        <strong><im><h3><label for="username" >Username:  </label><input id="username" type="text" name="user" Size="20" /> 
        
        <br><br><br><?php echo" &nbsp";echo" &nbsp";echo" &nbsp";echo" &nbsp";echo" &nbsp";echo" &nbsp";echo" &nbsp"; echo" &nbsp";echo" &nbsp";?>
        <input type="submit" name="submit" value="Submit" />
            </form>
        
          </div>
          
          <div class="column side">
            
          </div>
        </div>
        <div class="footer">
         
        </div>
        
          
        </body>
        </html>
      2. @yossrapage3:
        <?php
         
        //LDAP Bind paramters, need to be a normal AD User account.
        $ldap_password = '******';
        $ldap_username = '*****';
        $ldap_connection = ldap_connect("*****");
         
        if (FALSE === $ldap_connection){
            // Uh-oh, something is wrong...
         echo 'Unable to connect to the ldap server';
        }
         
        // 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, $ldap_password)){
         
         //Your domains DN to query
            $ldap_base_dn = 'DC=*****,DC=******';
          
         //Get standard users and contacts
            $search_filter ='CN=3363';
          
         //Connect to LDAP
         $result = ldap_search($ldap_connection, $ldap_base_dn, $search_filter);
          
            if (FALSE !== $result){
         $entries = ldap_get_entries($ldap_connection, $result);
          
         // Uncomment the below if you want to write all entries to debug somethingthing 
         //var_dump($entries);
          
         //Create a table to display the output 
         echo '<h2>AD User Results</h2></br>';
         echo '<table border = "1"><tr bgcolor="#cccccc"><td>Username</td><td>Last Name</td><td>First Name</td><td>Company</td><td>Department</td><td>Office Phone</td><td>Fax</td><td>Mobile</td><td>DDI</td><td>E-Mail Address</td><td>Home Phone</td></tr>';
          
         //For each account returned by the search
         for ($x=0; $x<$entries['count']; $x++){
          
         //
         //Retrieve values from Active Directory
         //
          
         //Windows Usernaame
         $LDAP_samaccountname = "";
          
         if (!empty($entries[$x]['samaccountname'][0])) {
         $LDAP_samaccountname = $entries[$x]['samaccountname'][0];
         if ($LDAP_samaccountname == "NULL"){
         $LDAP_samaccountname= "";
         }
         } else {
         //#There is no samaccountname s0 assume this is an AD contact record so generate a unique username
          
         $LDAP_uSNCreated = $entries[$x]['usncreated'][0];
         $LDAP_samaccountname= "CONTACT_" . $LDAP_uSNCreated;
         }
          
         //Last Name
         $LDAP_LastName = "";
          
         if (!empty($entries[$x]['sn'][0])) {
         $LDAP_LastName = $entries[$x]['sn'][0];
         if ($LDAP_LastName == "NULL"){
         $LDAP_LastName = "";
         }
         }
          
         //First Name
         $LDAP_FirstName = "";
          
         if (!empty($entries[$x]['givenname'][0])) {
         $LDAP_FirstName = $entries[$x]['givenname'][0];
         if ($LDAP_FirstName == "NULL"){
         $LDAP_FirstName = "";
         }
         }
          
         //Company
         $LDAP_CompanyName = "";
          
         if (!empty($entries[$x]['company'][0])) {
         $LDAP_CompanyName = $entries[$x]['company'][0];
         if ($LDAP_CompanyName == "NULL"){
         $LDAP_CompanyName = "";
         }
         }
          
         //Department
         $LDAP_Department = "";
          
         if (!empty($entries[$x]['department'][0])) {
         $LDAP_Department = $entries[$x]['department'][0];
         if ($LDAP_Department == "NULL"){
         $LDAP_Department = "";
         }
         }
          
         //Job Title
         $LDAP_JobTitle = "";
          
         if (!empty($entries[$x]['title'][0])) {
         $LDAP_JobTitle = $entries[$x]['title'][0];
         if ($LDAP_JobTitle == "NULL"){
         $LDAP_JobTitle = "";
         }
         }
          
         //IPPhone
         $LDAP_OfficePhone = "";
          
         if (!empty($entries[$x]['ipphone'][0])) {
         $LDAP_OfficePhone = $entries[$x]['ipphone'][0];
         if ($LDAP_OfficePhone == "NULL"){
         $LDAP_OfficePhone = "";
         }
         }
          
         //FAX Number
         $LDAP_OfficeFax = "";
          
         if (!empty($entries[$x]['facsimiletelephonenumber'][0])) {
         $LDAP_OfficeFax = $entries[$x]['facsimiletelephonenumber'][0];
         if ($LDAP_OfficeFax == "NULL"){
         $LDAP_OfficeFax = "";
         }
         }
          
         //Mobile Number
         $LDAP_CellPhone = "";
          
         if (!empty($entries[$x]['mobile'][0])) {
         $LDAP_CellPhone = $entries[$x]['mobile'][0];
         if ($LDAP_CellPhone == "NULL"){
         $LDAP_CellPhone = "";
         }
         }
          
         //Telephone Number
         $LDAP_DDI = "";
          
         if (!empty($entries[$x]['telephonenumber'][0])) {
         $LDAP_DDI = $entries[$x]['telephonenumber'][0];
         if ($LDAP_DDI == "NULL"){
         $LDAP_DDI = "";
         }
         }
          
         //Email address
         $LDAP_InternetAddress = "";
          
         if (!empty($entries[$x]['mail'][0])) {
         $LDAP_InternetAddress = $entries[$x]['mail'][0]; 
         if ($LDAP_InternetAddress == "NULL"){
         $LDAP_InternetAddress = "";
         }
         }
          
         //Home phone
         $LDAP_HomePhone = "";
          
         if (!empty($entries[$x]['homephone'][0])) {
         $LDAP_HomePhone = $entries[$x]['homephone'][0];
         if ($LDAP_HomePhone == "NULL"){
         $LDAP_HomePhone = "";
         }
         }
          
         echo "<tr><td><strong>" . $LDAP_samaccountname ."</strong></td><td>" .$LDAP_LastName."</td><td>".$LDAP_FirstName."</td><td>".$LDAP_CompanyName."</td><td>".$LDAP_Department."</td><td>".$LDAP_OfficePhone."</td><td>".$LDAP_OfficeFax."</td><td>".$LDAP_CellPhone."</td><td>".$LDAP_DDI."</td><td>".$LDAP_InternetAddress."</td><td>".$LDAP_HomePhone."</td></tr>";
         
          
         } //END for loop
         } //END FALSE !== $result
          
         ldap_unbind($ldap_connection); // Clean up after ourselves.
         echo("</table>"); //close the table
         
        } //END ldap_bind
         
        ?>