 |
[PHP]
ขอตัวอย่างหรือวิธีการเขียน PHP จัดการข้อมูลใน AD(Active Directory) ใน Server ครับ |
|
 |
|
|
 |
 |
|
ตอนนี้คิดว่า เชื่อมต่อได้แล้วด้วย Code
Code (PHP)
01. <META HTTP-EQUIV= "Content-Type" CONTENT= "text/html; charset=tis-620" >
02. <?php
03.
04.
05.
06.
07. $username = "admin" ;
08. $pass = "admin" ;
09.
10. if ( $username !=null and $pass !=null)
11. {
12. $server = "10.10.10.10" ;
13. $user = $username . "@test.org" ;
14.
15. $ad = ldap_connect( $server );
16. if (! $ad ) {
17. die ( "Connect not connect to " . $server );
18. echo "ไม่สามารถติดต่อ server ได้" ;
19. exit ();
20. } else {
21. $b = @ldap_bind( $ad , $user , $pass );
22. if (! $b ) {
23. die ("<br><br>
24. <div align= 'center' > ท่านกรอกรหัสผ่านผิดพลาด
25. <br>
26. </div>
27. <meta http-equiv= 'refresh' content= '3 ;url=index.php' >");
28. } else {
29.
30.
31. session_start();
32. echo "เชื่อมต่อได้แล้ว" ;
33.
34. }
35.
36. }
37.
38. }
39.
40. ?>
ตอนนี้มันขึ้น "เชื่อมต่อได้แล้ว" แล้ว แต่ผมติดที่จะเข้าไปจัดการข้อมูล เช่นการเข้าไปเปลี่ยน Password หรือ แค่แสดงข้อมูล
ผมลองแก้ Code แบบข้างล่างดูแต่ก็ยังไม่ได้ครับ
Code (PHP)
01. function ldap_login( $ds , $username , $password , $ou , $suffix ){
02. $i =0;
03. while (1){
04. $binddn = "uid=$username,ou=" . $ou [ $i ]. "," . $suffix ;
05. @ $ldapbind = ldap_bind( $ad , $binddn , $password );
06. if ( $ldapbind ){
07. return true;
08. break ;
09. } else {
10. if ( $i ==3){
11. ldap_close( $ds );
12. return false;
13. break ;
14. }
15. }
16. $i ++;
17. }
18. }
19.
20. $ou = array ( "student" , "staff" , "unistaff" );
21. $suffix_string = "dc=psu,dc=pn" ;
22. $USER = "3114" ;
23. $PASSWORD = "sanji007" ;
24. if (ldap_login( $ad , $USER , $PASSWORD , $ou , $suffix_string )){
25. echo "สวัสดีครับ" ;
26. } else {
27. echo "User หรือ Password ผิด" ;
28. }
โปรดช่วยแนะนำหน่อยครับ
|
 |
 |
 |
 |
Date :
2018-03-22 16:23:43 |
By :
yutthanagorn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จากที่ผมพยายาม ศึกษาดูแล้วนะครับ คือยังไม่เข้าใจ โดยผมใช้ จาก ตัวอย่างนี้ https://www.thaicreate.com/php/php-user-authentication-active-directory.html ซึ่งก็สามารถเชื่อมต่อได้ไปยัง Server ได้ แต่ยังไม่เข้าใจการที่จะดึงข้อมูลเอาโชว์ เพิ่ม หรือแก้ไข โดยเป้าหมายหลักๆคือ อยากแค่ เปลี่ยน Password ให้ได้
Code (PHP)
01. <META HTTP-EQUIV= "Content-Type" CONTENT= "text/html; charset=tis-620" >
02. <?php
03.
04.
05.
06.
07. $username = "admin" ;
08. $pass = "admin" ;
09.
10. if ( $username !=null and $pass !=null)
11. {
12. $server = "10.10.10.10" ;
13. $user = $username . "@test.org" ;
14.
15. $ad = ldap_connect( $server );
16. if (! $ad ) {
17. die ( "Connect not connect to " . $server );
18. echo "ไม่สามารถติดต่อ server ได้" ;
19. exit ();
20. } else {
21. $b = @ldap_bind( $ad , $user , $pass );
22. if (! $b ) {
23. die ("<br><br>
24. <div align= 'center' > ท่านกรอกรหัสผ่านผิดพลาด
25. <br>
26. </div>
27. <meta http-equiv= 'refresh' content= '3 ;url=index.php' >");
28. } else {
29.
30.
31. session_start();
32. echo "เชื่อมต่อได้แล้ว" ;
33.
34. }
35.
36. }
37.
38. }
39.
40. ?>
ท่ั้งนี้ผมลองตาม Link https://www.thaicreate.com/community/ldap2.html ซึ่งก็มีข้อสงสัยหลายอย่างมากที่ไม่ใจ พยายามทำตามทีละ Step by step แล้วเช่น หัวข้อที่ 3 $ds=ldap_connect(?localhost?,?389?) ทำไมต้องมี ? แล้วพอใส่ไปก็ error ตรง ?
หรือตาม code
Code (PHP)
01. <?php
02. function ldap_login( $ds , $username , $password , $ou , $suffix ){
03. $i =0;
04. while (1){
05. $binddn = "uid=$username,ou=" . $ou [ $i ]. "," . $suffix ;
06. @ $ldapbind = ldap_bind( $ds , $binddn , $password );
07. if ( $ldapbind ){
08. return true;
09. break ;
10. } else {
11. if ( $i ==3){
12. ldap_close( $ds );
13. return false;
14. break ;
15. }
16. }
17. $i ++;
18. }
19. }
20.
21. $ds =ldap_connect( "10.10.10.10" );
22. $USER = "administrator" ;
23. $PASSWORD = "Password" ;
24. $ou = array ( "student" , "staff" , "unistaff" );
25. $suffix_string = "dc=imlab,dc=org" ;
26. if (ldap_login( $ds , $USER , $PASSWORD , $ou , $suffix_string )){
27. echo "สวัสดีครับ" ;
28. } else {
29. echo "User หรือ Password ผิด" ;
30. }
31. ?>
ซึ่งผมไม่เข้าใจความหมายมันครับ เช่น
ตรง $binddn = "uid=$username,ou=".$ou[$i].",".$suffix; uid,ou คืออะไร
ตรง @$ldapbind = ldap_bind($ds, $binddn, $password); ทำไมต้องมี @ พอใส่ก้ error ไม่ใส่ก็ error แบบอื่น
ตรง $ou = array("student","staff","unistaff"); คือค่าอะไร
ตรง "dc=imlab,dc=org"; ผมเข้าใจถูกใช่ไหมว่าเป็น Domain
แล้วพอไปอ่านตัวอย่างต่อไป ก็ยิ่ง งง ค่าเข้าไปอีกใครพอจะมี Code ตัวอย่างที่เข้าใจง่ายหรืออธิบายดีๆหน่อยไหมครับ
|
 |
 |
 |
 |
Date :
2018-03-27 18:57:15 |
By :
yutthanagorn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|