PHP ldap connection always turns out true
<p>I am trying to make an connection with an active directory to authenticate a user.
However it doesnt matter what you type in as it will put you trough either way.</p>

<p>I am not even sure if I make the right connection.
as host name I currently use [ip adress].[domain].nl
and I do not know if this is even possible, but it didn't turn out an error when I checked the ldap_connect() for errors.</p>

<p>so if you guys would like to look over the code and give me tips, that would be great. I left out the connection details for security reasons.</p>

<p>sry if this is a stupid question but I have bo idea on whats wrong.
Thanks in advance.</p>

<pre><code>class LOGIN{
        public function login($data){

            $user = $data["username"];
            $password = $data["password"];
            $host = 'ldap://[ip adress]/[domain].nl';
            $domain = '[domain].nl';
            $basedn = 'dc=[domain],dc=nl';

            $ad = ldap_connect($host.$domain,389) or die('Could not connect to LDAP server.');

            ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
            ldap_set_option($ad, LDAP_OPT_REFERRALS, 0);

            //$bind = ldap_bind($ad, "$user@$domain", $password) or die('Could not bind to AD.');

            if(@ldap_bind($ad, "$user"."@"."$domain", $password)){

                $result = "Authenticated";

            }else{
                $result = "Invalid Credential";
            }               

            return $result;
        }
    }
}

$login = new LOGIN; 
</code></pre>

<p>And this is the form to log in:</p>

<pre><code>&lt;?php 
if(isset($_POST['username']) &amp;&amp; isset($_POST['password']) &amp;&amp; !empty($_POST['username']) &amp;&amp; !empty($_POST['password'])){

require_once("classes/class_login.php");

$result = $login-&gt;login($_POST);

}   
?&gt;

&lt;form action="#" method="POST"&gt;
    &lt;?php if(!empty($result)){echo "&lt;p&gt;".$result."&lt;/p&gt;";} ?&gt;
    &lt;pre&gt;
    &lt;label for="username"&gt;Username: &lt;/label&gt;&lt;input id="username" type="text" name="username" /&gt; 
    &lt;label for="password"&gt;Password: &lt;/label&gt;&lt;input id="password" type="password" name="password" /&gt;       

    &lt;input type="submit" name="submit" value="Submit" /&gt;
    &lt;/pre&gt;
&lt;/form&gt;
</code></pre>