|
 |
|
สอบถามเรื่อง การ authenticate ผ่าน active directory ครับ |
|
 |
|
|
 |
 |
|
Code (PHP)
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=tis-620">
<?php
$username = $_POST["username"];
$pass = $_POST["password"];
if($username !=null and $pass !=null)
{
$server = " 192.168.5.40"; //dc1-nu
$user = $_POST["username"]."@nu.local";
// connect to active directory
$ad = ldap_connect($server);
if(!$ad) {
die("Connect not connect to ".$server);
// include("chk_login_db.php");
echo "ไม่สามารถติดต่อ server มหาลัยเพื่อตรวจสอบรหัสผ่านได้";
exit();
} else {
$b = @ldap_bind($ad,$user,$pass);
if(!$b) {
die("<br><br>
<div align='center'> ท่านกรอกรหัสผ่านผิดพลาด
<br>
</div>
<meta http-equiv='refresh' content='3 ;url=index.php'>");
} else {
//login ผ่านแล้วมาทำไรก็ว่าไป
session_start();
}
echo "<script type=text/javascript>";
echo "alert('ยินดีต้อนรับ ')";
echo "</script>";
echo "<meta http-equiv='refresh' content='0 ;url= index.php?case_i=13'>";
exit();
}
}
?>
คือเจ้านายผมเค้าให้ แค่ user, password มา ให้ไป authen กับ AD อยากสอบถามว่า
$user = $_POST["username"]."@nu.local";
@nu.local นี่มาจากไหนครับ คือทางเค้าต้องให้มา หรือเราไปเอามาจากไหน มันคืออะไร
แล้วโค้ดนี้ครับ
Code (PHP)
function ldap_login($ds,$username,$password,$ou,$suffix){
$i=0;
while(1){
$binddn = "uid=$username,ou=".$ou[$i].",".$suffix;
@$ldapbind = ldap_bind($ds, $binddn, $password);
if ($ldapbind){
return true;
break;
}else{
if($i==3){
ldap_close($ds);
return false;
break;
}
}
$i++;
}
}
$ou = array("student","staff","unistaff");
$suffix_string = "dc=psu,dc=pn";
if(ldap_login($ds,$USER,$PASSWORD,$ou,$suffix_string)){
echo?สวัสดีครับ?;
}else{
echo?User หรือ Password ผิด?;
}
$ou = array("student","staff","unistaff");
$suffix_string = "dc=psu,dc=pn";
สองตัวแปรนี้คืออะไรมาจากไหนอ่ะครับ
ขอบคุณครับ
Tag : PHP, MySQL, JavaScript, Ajax, jQuery

|
|
 |
 |
 |
 |
Date :
2014-08-07 16:49:48 |
By :
เด็กโง่ |
View :
849 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 05
|