Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- $ldapAddress = "10.0.0.3";
- $ldapPort = 389;
- $ldap=ldap_connect($ldapAddress, $ldapPort) or die("Error: Unable to connect to the LDAP Server");
- $host="localhost";
- $username="***";
- $password="***";
- $db_name="***";
- $tbl_name="***";
- mysql_connect("$host", "$username", "$password")or die("cannot connect");
- mysql_select_db("$db_name")or die("cannot select DB");
- $myusername = stripslashes($_POST['korIme']);
- $mypassword = stripslashes($_POST['lozinka']);
- ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
- ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
- if (!$bind=ldap_bind($ldap, 'peta\\'.$myusername, $mypassword)) {
- echo "GreΕ‘ka";
- } else {
- $dn = "DC=peta, DC = local";
- $sr=ldap_search($ldap, $dn, "sAMAccountName=$myusername");
- $inf = ldap_get_entries($ldap, $sr);
- $info = $inf[0];
- for ($i = 0; $i < count($info); $i++)
- {
- $t = $info[$i];
- //echo $i." ".$info[$i]." ".$info[$t][0]."<br/>";
- //echo $info['sn'][0]." ".$info['givenname'][0];
- }
- $rezultat = mysql_query("SELECT korisnickoime FROM ldapkorisnici WHERE korisnickoime = '$myusername'");
- $n = mysql_num_rows($rezultat);
- if ($n == 1)
- {
- session_register("myusername");
- session_register("password");
- header("location:index.php");
- }
- else
- {
- $ime = $info['givenname'][0];
- $prezime = $info['sn'][0];
- echo "Niste ovlaΕ‘teni za pristup administraciji";
- }
- ldap_close($ldap);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment