Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- if(!empty($_POST['username']) && !empty($_POST['password'])){
- $_SESSION['user'] = $_POST['username'];
- $adServer = "***********";
- $ldap = ldap_connect($adServer);
- $username = $_POST['username'];
- $password = $_POST['password'];
- $ldaprdn = $username.'@***********';
- ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
- ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
- $bind = @ldap_bind($ldap, $ldaprdn, $password);
- if ($bind)
- {
- $filter="(sAMAccountName=$username)";
- $result = ldap_search($ldap,"DC=***********,DC=com",$filter);
- ldap_sort($ldap,$result,"sn");
- $info = ldap_get_entries($ldap, $result);
- for ($i=0; $i<$info["count"]; $i++)
- {
- if($info['count'] > 1)
- break;
- if($info[$i]["department"][0] == IT) {
- $z="<p>Zalogowany <strong> ". $info[$i]["givenname"][0] ." " . $info[$i]["sn"][0] ."</strong>";
- }
- else {
- echo "Brak uprawnień do przeglądania zawartości. Żegnam. ";
- exit();
- }
- }
- @ldap_close($ldap);
- <html>
- <?php echo $z ?>
- <a href="logout.php" style="text-decoration:none;">Wyloguj</a>
- </html>
- <?php
- }
- else
- {
- $msg = "Nieprawidłowe dane. <a href=\"javascript:history.go(-1);\">Wstecz</a>.";
- echo $msg;
- }
- }
- else
- {
- ?>
- <div>
- <form action="#" method="POST">
- <label for="username">Login: </label><input id="username" type="text" name="username" /> <br /> <br />
- <label for="password">Hasło: </label><input id="password" type="password" name="password" /> <br /> <br />
- <input type="submit" name="submit" value="Zaloguj" />
- </form>
- </div>
- <?php
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement