SHOW:
|
|
- or go back to the newest paste.
| 1 | <?php | |
| 2 | session_start(); | |
| 3 | $ldapAddress = "10.0.0.3"; | |
| 4 | $ldapPort = 389; | |
| 5 | $ldap=ldap_connect($ldapAddress, $ldapPort) or die("Error: Unable to connect to the LDAP Server");
| |
| 6 | $host="localhost"; | |
| 7 | $username="***"; | |
| 8 | $password="***"; | |
| 9 | $db_name="***"; | |
| 10 | $tbl_name="***"; | |
| 11 | mysql_connect("$host", "$username", "$password")or die("cannot connect");
| |
| 12 | mysql_select_db("$db_name")or die("cannot select DB");
| |
| 13 | $myusername = stripslashes($_POST['korIme']); | |
| 14 | $mypassword = stripslashes($_POST['lozinka']); | |
| 15 | ||
| 16 | ||
| 17 | ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3); | |
| 18 | ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0); | |
| 19 | ||
| 20 | if (!$bind=ldap_bind($ldap, 'peta\\'.$myusername, $mypassword)) {
| |
| 21 | echo "GreΕ‘ka"; | |
| 22 | } else {
| |
| 23 | $dn = "DC=peta, DC = local"; | |
| 24 | - | $sr=ldap_search($ldap, $dn, "sAMAccountName=$username"); |
| 24 | + | $sr=ldap_search($ldap, $dn, "sAMAccountName=$myusername"); |
| 25 | $inf = ldap_get_entries($ldap, $sr); | |
| 26 | $info = $inf[0]; | |
| 27 | ||
| 28 | for ($i = 0; $i < count($info); $i++) | |
| 29 | {
| |
| 30 | $t = $info[$i]; | |
| 31 | //echo $i." ".$info[$i]." ".$info[$t][0]."<br/>"; | |
| 32 | //echo $info['sn'][0]." ".$info['givenname'][0]; | |
| 33 | } | |
| 34 | $rezultat = mysql_query("SELECT korisnickoime FROM ldapkorisnici WHERE korisnickoime = '$myusername'");
| |
| 35 | $n = mysql_num_rows($rezultat); | |
| 36 | if ($n == 1) | |
| 37 | {
| |
| 38 | session_register("myusername");
| |
| 39 | session_register("password");
| |
| 40 | header("location:index.php");
| |
| 41 | } | |
| 42 | else | |
| 43 | {
| |
| 44 | $ime = $info['givenname'][0]; | |
| 45 | $prezime = $info['sn'][0]; | |
| 46 | echo "Niste ovlaΕ‘teni za pristup administraciji"; | |
| 47 | ||
| 48 | } | |
| 49 | ldap_close($ldap); | |
| 50 | } | |
| 51 | ?> |