I have a login controller that has a function that connects to LDAP using my domain credentials.
class Login extends MX_Controller {
const USER = "DOMAINACCOUNT";
const PASS = "DoM@inP@ssw0rd";
public function checkWW930() {
$ldapserver = "ldap://ww930.sampledomain.net";
$dn = 'dc=ww930,dc=sampledomain,dc=net';
$ldapconn = ldap_connect($ldapserver) or die("Could not connect to $ldaphost");
//ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
//ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
$user = self::USER;
$pass = self::PASS;
$bind = @ldap_bind($ldapconn, 'ww930\\'.$user, $pass);
$filter = "(samaccountname=". $this->input->post('username') .")";
$result = ldap_search($ldapconn, $dn, $filter);
$info = ldap_get_entries($ldapconn, $result);
if($info["count"] > 0) {
return TRUE; // account exists in ww930 domain
} else {
return FALSE; // account does not exist in ww930 domain
}
This works fine but I would like to save my credentials in a separate file so I can use it in other controllers if needed. Also I want to save it in a single file so that if my password expires, I only have to update one file. I am thinking to put my credentials in credentials.php file then add include('credentials.php'); Can someone help me how to implement it? Many thanks.
constants.php, in that you can define all the constants.