我試圖創建一個php腳本來檢查我的ldap目錄中是否存在用戶名和密碼組合。我會發布我到目前爲止。創建一個PHP腳本,將在LDAP中檢查用戶名和密碼組合
<?php
$username = $_POST["username"];
$password = $_POST["password"];
$ldapconn = ldap_connect("localhost")
or die("Could not connect to LDAP server.");
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$ldaprdn = "cn=$username,dc=designstudio1,dc=com";
$ldappass = "$password";
if ($ldapconn) {
$ldapbind = ldap_bind($ldapconn, $ldarprdn, $ldarppass);
if ($ldapbind) {
echo "Welcome back, $username!";
} else {
echo "Authentication failed. Please check your username/password and try again.";
}
}
?>
如果你需要它,這裏是我的PHP的形式。
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<meta charset="UTF-8">
<title>Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form id="contact-form" action="script.php" method="post">
<input type="hidden" name="redirect" />
<ul>
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="" />
<label for="password">Password:</label>
<input type="password" name="password" id="password" value="" />
<input type="submit" value="submit" />
</ul>
</form>
</body>
</html>
我輸入的每個用戶名和密碼(有效或無效),它總是顯示歡迎信息。
我在php和ldap中仍然很綠,因爲我的代碼清楚地顯示了這一點。任何幫助,將不勝感激。
我還會編輯我的代碼,因爲我建議更改以及我發現的任何不適合的內容。
拼寫計數@Sammitch建議。打開'error_reporting',它應該抱怨所有你拼錯的變量名稱。 – Sammitch
Oy。其中大部分來自我的老師。大聲笑這是令人尷尬的。我必須這樣做,看看它是否有效。感謝您的領導! – Zazabar
所以......這是拼寫錯誤的ldap變量? – Zazabar