title: How to Connect to Okta LDAP?
body: <p>So, I have an LDAP directory with Okta set up. I am having trouble connecting to it using PHP. Here's my code:</p>
  <pre><code>$domain = 'phishingboxdecember15thaccount.ldap.okta.com';
  $username = 'USERNAME';
  $password = 'PASSWORD';
  $ldapconfig['host'] = '44.234.52.17';  // I got this by pinging the domain. I guess that's correct?
  $ldapconfig['port'] = 636;
  $ldapconfig['basedn'] = 'dc=phishingboxdecember15thaccount,dc=okta,dc=com';
  
  $ds=ldap_connect($ldapconfig['host'], $ldapconfig['port']);
  
  ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
  ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
  
  $dn=&quot;ou=users,&quot;.$ldapconfig['basedn'];
  $bind=ldap_bind($ds, $username .'@' .$domain, $password);
  print_r($bind);
  $isITuser = ldap_search($bind,$dn,'(&amp;(objectClass=User)(sAMAccountName=' . $username. '))');
  if ($isITuser) {
      echo(&quot;Login correct&quot;);
  } else {
      echo(&quot;Login incorrect&quot;);
  }
  </code></pre>
  <p>Yet this never works. Always get &quot;Login incorrect&quot;, and I am certain that I'm using the correct password (although, I'm not sure about the username part - I just use the username I enter to login to my Okta admin account, I'm assuming that's correct?).</p>
  <p>Do you have any ideas/tips on how I can connect to the Okta LDAP using PHP?</p>