0

HI Am trying to connect and unbind the server and port ldap connection using php.

Here is my code:

$hostname = 'ldaps://www.google.com';
$port = 636;
echo "ldap check";
$lp = ldap_connect($hostname,$port);
echo "servername";
echo $_SERVER['PHP_AUTH_USER'];
$username = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
if ($bind = @ldap_bind($lp, $username.$hostname, $password)){
    echo "Hello";
    ldap_unbind($lp,$username,$password);
}

Failure:

But am not connecting with the ldap connection.PLease help me to fix the code.

2
  • 1
    what is the error message that you are getting ? Commented Dec 7, 2017 at 14:37
  • am not getting any error message simply my page loads and it is not printing any error messages and unable to see others contents also@RamC Commented Dec 8, 2017 at 6:13

1 Answer 1

1

When I read your code right, there are two issues:

  1. The port you are giving will never be used in the ldap_connect. The docs clearly state that using the port as second argument to ldap_connect is deprecated and will only be used when you pass a servername or IP. But you are passing a URI, so that needs to include the port as well.

  2. You are trying to bind as $username . $hostname. So you are tying to conntect 'someuser' as someuserldaps://www.google.com - I doubt that that will ever work. You probably want something like [email protected]...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.