CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.

YesSoftware Forums -> CodeCharge Studio -> PHP

 AD (ldap) authentication using WampServer 2.2 [SOLVED]

Print topic Send  topic

Author Message

Posts: 67
Posted: 03/27/2018, 8:47 AM Quote message

Here's my setup and what I did on my testing server. WampServer 2.2 running php 5.3.10, Apache 2.2.21 on Windows 2012 R2. The key is getting the php_ldap library and driver to work. Make sure that the following files are COPIED from /wamp/bin/php/php5.3.10 to /wamp/bin/apache/apache2.2.21/bin: libsasl.dll, libeay32.dll,ssleay32.dll. The last 2 were already there in my case. The coding requires calling the ldap connection function and authenticating the user, then setting the Session Variables required by CCS5. If you don't set these variables the target page never loads and you are kicked back to the login page. I did not modify common.php. I just didn't call CCLoginUser().

Make a new login page using the CCS5 builder or modify your existing. Here is the CCS5 code with my modifications. Note that words between <> must be put in by you. Don't include the <>:

//BindEvents Method @1-D3E6B248  
function BindEvents()  
    global $Login;  
    global $CCSEvents;  
    $Login->Button_DoLogin->CCSEvents["OnClick"] = "Login_Button_DoLogin_OnClick";  
//End BindEvents Method  
//Login_Button_DoLogin_OnClick @3-1454CF55  
function Login_Button_DoLogin_OnClick(& $sender)  
    $Login_Button_DoLogin_OnClick = true;  
    $Component = & $sender;  
    $Container = & CCGetParentContainer($sender);  
    global $Login; //Compatibility  
//End Login_Button_DoLogin_OnClick  
//Login @4-A8229250  
    global $CCSLocales;  
    global $Redirect;  
    $username = $Container->login->Value;  
    $password = $Container->password->Value;  
    if ($Container->autoLogin->Value != $Container->autoLogin->CheckedValue) {  
        CCSetCookie("ccPOTESTLogin", "");  
	$ldap = ldap_connect("<your domain controller hostname or IP address");  
	ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);  
	ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);  
	//ldap_set_option($ldap, LDAP_OPT_DEBUG_LEVEL, 7);  
	$ldaprdn = '<your Domain name>'."\\".$username;  
    //die( "LDAP Failed To Connect: ".ldap_error($ldap));  
	if (!$bind = ldap_bind($ldap, $ldaprdn, $password))  
		//die("user: ".$Container->password->Value);  
//    if ( !CCLoginUser( $Container->login->Value, $Container->password->Value)) {  
        $Login_Button_DoLogin_OnClick = 0;  
        CCSetCookie("ccPOTESTLogin", "");  
	} else {  
	//echo("ldap is good");  
		//add the next line to establish CCS session variables (id, group, username)  
        global $Redirect;  
        if ($Container->autoLogin->Value == $Container->autoLogin->CheckedValue) {  
            $ALLogin    = $Container->login->Value;  
            $ALPassword = $Container->password->Value;  
            CCSetALCookie($ALLogin, $ALPassword);  
       // die("ready to redirect: ".ccGetParam("ret_link"));  
           //die(ccGetUserID()."; ".ccgetGroupID()."; ".ccgetUserLogin());  
        $Redirect = CCGetParam("ret_link", $Redirect);  
        $Login_Button_DoLogin_OnClick = 1;  
//End Login  
//Close Login_Button_DoLogin_OnClick @3-0EB5DCFE  
    return $Login_Button_DoLogin_OnClick;  
//End Close Login_Button_DoLogin_OnClick  
//Page_BeforeInitialize @1-0242CABD  
function Page_BeforeInitialize(& $sender)  
    $Page_BeforeInitialize = true;  
    $Component = & $sender;  
    $Container = & CCGetParentContainer($sender);  
    global $login; //Compatibility  
//End Page_BeforeInitialize  
//Custom Code @9-2A29BDB7  
// -------------------------  
    // Write your own code here.  
// -------------------------  
//End Custom Code  
//Close Page_BeforeInitialize @1-23E6A029  
    return $Page_BeforeInitialize;  
//End Close Page_BeforeInitialize  
Function SetUserVariables($username)  
$db = new clsDBSecurity();  
$sql = "Select userid, groupid from tblUsers WHERE username = ".$db->ToSQL($username, ccsText);  
$result = $db->next_record();  
//{die("userID= ". $db->f("userid"));  
ccSetSession("UserID", $db->f("userid"));  
ccSetSession("GroupID", $db->f("groupid"));  
CCSetSession("UserAddr", $_SERVER["REMOTE_ADDR"]);  

You can verify this is working by changing a user's password from your security database and then trying to log in. Try an incorrect password to test for that also.

Happy coding.
View profile  Send private message

Add new topic Reply to topic Subscribe to topic   

These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit

Web Database

Join thousands of Web developers who build Web applications with minimal coding.

Home   |    Search   |    Members   |    Register   |    Login

Powered by UltraApps Forum created with CodeCharge Studio
Copyright 2003-2004 by  and YesSoftware, Inc.