Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6089141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:03:59+00:00 2026-05-23T12:03:59+00:00

I am having a little trouble with my PHP LDAP login. My first bind

  • 0

I am having a little trouble with my PHP LDAP login. My first bind is successful, but my second bind is not even if the credentials are correct. I tried using the credentials I use to the second bind in the first one to make sure it worked, and sure enough it can bind it at the first one. Why am I not being able to bind the second time?

<?php
// Define $myusername and $mypassword
$username=$_POST['username'];
$password=$_POST['password'];

// using ldap bind
$ldaprdn  = 'uid=MYUID,ou=special,ou=people,o=myo.com,dc=mydc,dc=com';     // ldap rdn or dn
$ldappass = 'PASSWORD';  // associated password

// connect to ldap server
$ldapconn = ldap_connect("ldaps://MYLDAPSERVER", ###)
    or die("Could not connect to LDAP server.");

if ($ldapconn) 
{
    // binding to ldap server
    $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);

    // verify binding
    if ($ldapbind) 
    {
        $result = ldap_search($ldapconn, "ou=people,o=myo.com,dc=mydc,dc=com", "uid=$username");
        $info = ldap_get_entries($ldapconn, $result);
        $userdn = $info[0]["dn"];
        $count = $info["count"]; 
        ldap_unbind($ldapconn);

        if ($count == 1)
        {
            $ldapbinduser = ldap_bind($ldapconn, $userdn, $password);
            if ($ldapbinduser) 
            {
                echo "Sucess you made it all the way<br />";
            }
            else
            {
                echo "Invalid Login Details, please try again(1001)";
            }
        }
        else
        {
            echo "Invalid Login Details, please try again(1002)";
        }
    } 
    else 
    {
        echo "LDAP bind failed(1000)";
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:04:00+00:00Added an answer on May 23, 2026 at 12:04 pm

    Although its name might implicate something different, ldap_unbind() actually kills the connection handle so that the connection is not usable any more after an unbind. Remove the ldap_unbind() call from your code and everything should work as expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having a little trouble with running a php script in the background. I
I'm just getting started with using php DOMDocument and am having a little trouble.
I'm just getting started with using php DOMDocument and am having a little trouble.
I am creating a file tree using PHP & jQuery, but I'm having trouble
I am having a little trouble with the following php statement: if (!userIsLoggedIn()) {
I'm having a little trouble with a query I've written (please see below). <?php
This is probably a simple issue but i'm having a little trouble with it.
I'm having a little trouble having a div to adjust to the correct height,
I'm having little trouble creating a script working with URLs. I'm using urllib.urlopen() to
I m having little trouble finding a relation between the movement at centre and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.