I'm trying to learn PHP and i'm doing my first login connection page to my Active Directory, i've already done those two pages:
form.php:
<HTML>
<body>
<form action="ADconnect" method="post">
<p>Votre login : <input type="text" name="login"/></p>
<p>Votre password : <input type="password" name="password"/></p>
<p><input type="submit" value="OK"></p>
</form>
</body>
</HTML>
ADconnect.php:
<?php
//check var
$check_password = $_POST['password'];
$check_dn= $_POST['login'];
//display of check var
echo $check_password;
echo "<br>";
echo $check_dn;
echo "<br>";
//AD's connexion var
$AD_con = ldap_connect("ADname") or die("could not connect to AD");
$AD_dn = "CN=".ldap_connect('$_POST['login']').",OU=XXX,OU=XXX,DC=XXX,DC=XXX";
$AD_password = ldap_connect('$_POST['password']');
echo $AD_dn;
echo "<br>";
//what i've tried to convert the AD's var:
//convert of $AD_con and $AD_password
//$AD_dn1 = strval($AD_dn);
//$AD_password1 = strval($AD_password);
//display of the converts
//echo $AD_dn1;
//echo $AD_password1;
//connect function
if (isset($_POST['login']) && $_POST['password'] == 0){
if (ldap_bind($AD_con, $AD_dn, $AD_password)){
include 'frontpage.php';
}
else{
echo "invalid user/pass or other error";
}
}
else
echo "var aren't correctly collect";
?>
I have an error when i'm trying to test those two pages and that's what i get:
pitword
Pit wasntme
CN=Resource id #7,OU=XXX,OU=XXX,DC=XXX,DC=XXX
A PHP Error was encountered
Severity: Warning
Message: ldap_bind() expects parameter 3 to be string, resource given
Filename: pages/ADconnect.php
Line Number: 30
Backtrace:
File: C:\wamp64\www\test\application\views\pages\ADconnect.php
Line: 30
Function: ldap_bind
File: C:\wamp64\www\test\application\controllers\pages.php
Line: 10
Function: view
File: C:\wamp64\www\test\index.php
Line: 315
Function: require_once
invalid user/pass or other error
So the values of my fields login and password are correctly recovered from one page to the other, and i've tested the connect function with plain text to see if the problem was coming from this. But i've reached my AD server. The problem seems to be that when i'm using the ldap_connect() function, the values of my variables $AD_dn and $AD_password are changed into "resource #7" and "resource #8". Normally it have to display "pit wasntme" for $AD_dn and "pitpass" $AD_password for the connect function.
By reading the error, i've understood that i've to convert them into strings, because it is what the ldap_bind needs for the second and third parameters. Which i've tried with what i've found on the net (i've put it in my comments below my last echo "
"), but the result is still the same.
If anyone can give a tip or an explanation on what i am doing wrong or on how can i recovers correctly (in the good format) my entered values sent by my form, it will be great.
Thanks to take time for reading this thread.
Ok thanks to whoever have try to help me but i've found the solution: i was using ldap_connect() on the $_POST['login'] and $_POST['password'] but if i remove this function all works correctly!