Page 1 of 1

Supposed Redeclaration Error

Posted: Fri Jan 08, 2010 3:33 pm
by Bigun
I'm getting some code written and I get an error that I cannot seem to find the cause of. Maybe I'm missing something

The Error:
Fatal error: Cannot redeclare authenticatead() (previously declared in D:\Inetpub\wwwcrud\functions.php:39) in D:\Inetpub\wwwcrud\functions.php on line 96
functions.php

Code: Select all

<?php
/*
** List of Existing Functions **
authenticatead($fnusername, $fnpassword) //Function that authenticates user to AD
    - returns array - $adresults
        - $adresults[0] - 1 for authenticated, 0 for not authenticated
        - $adresults[1] - Department
        - $adresults[2] - Permissions
 
pulluserdbinfo($username) //Function that pulls information about the user from the DB
    -returns mssql db handle
    
adtodb($username, $password)  //Function that pulls user's information from AD and puts it into the DB
    - returns array $userinfo
        - $userinfo[0] - E-mail Address
        - $userinfo[1] - Firstname
        - $userinfo[2] - Lastname
        - $userinfo[3] - Badge Number
 
startusersession($username, $badge, $firstname, $lastname, $email, $department, $permissions) //Starts a session with the user's information
 
endusersession() //Ends a user's session
 
caseexists($complaintno) //Checks for the existence of a case
    - returns number of cases found
    
startnewcase($complaintno, $badge, $datetime) //Inputs basic case data into DB
 
mssql_escape_string($string_to_escape) //Cleans URL variables for MSSQL use
    - returns cleaned variable
    
departmentcheck() //Check to see what department a case belongs to
    - not started
    
function pullcaseinfo() //Pulls basic case information
    - returns SQL row
*/
 
function authenticatead($fnusername, $fnpassword) //Function that authenticates user to AD
{
    include("./config.php");
    //Connection
    $ad = ldap_connect($host) or die( "Could not connect to Active Directory! Contact Helpdesk.<br>" );
    //Set LDAP Version Info
    ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3) or die ("Could not set ldap protocol<br>");
    ldap_set_option($ad, LDAP_OPT_REFERRALS,0);
    //Bind to AD - Actual Username Authentication Test
    if (!($bd = ldap_bind($ad, $fnusername . $usersuffix, $fnpassword)))
    {
        //Did not pass AD authentication
        $adresults[0] = "0";
    } else {
        //Passed AD authentication
        $adresults[0] = "1";
    }
    
    if ($adresults[0] == "1") {
        //Passed authentication, see what CRUD groups they are part of
        
        //See if user is part of any groups in AD
        $bd = ldap_bind($ad, $fnusername . $usersuffix, $fnpassword) or die ("Could not bind<br>");
        
        // Create the DN
        $dn = "****Taken out for security****";
        
        // Specify only those parameters we're interested in displaying
        $attrs = array("displayname");
        
        // Create the filter from the search parameters
        $filter = "(samaccountname=" . $fnusername . ")";
        
        $search = ldap_search($ad, $dn, $filter) or die ("ldap search failed<br>");
        
        $entries = ldap_get_entries($ad, $search);
        
        for ($i=0; $i<$entries[0]["memberof"]["count"]; $i++) {
            if (substr($entries[0]["memberof"][$i], 0, 7) == "CN=CRUD") {
                $sections = explode(",", $entries[0]["memberof"][$i]);
                $permissions = explode("_", $sections[0]);
            }
        }
    
        ldap_unbind($ad);
        
        if (isset($permissions)) {
            if ($permissions[1] == "Admin") {
                $adresults[1] = "Admin";
                $adresults[2] = "Admin";
            } else {
                $adresults[1] = $permissions[1];
                $adresults[2] = $permissions[2];
            }
        }
    }
    
    return $adresults;
}
?>
 

Re: Supposed Redeclaration Error

Posted: Fri Jan 08, 2010 4:09 pm
by manohoo
Take a look at the contents of config.php. Most likely it will have an include statement to functions.php, where the variable has already been declared.

Re: Supposed Redeclaration Error

Posted: Fri Jan 08, 2010 7:13 pm
by Bigun

Code: Select all

<?php
//SQL Information
$MSSQLServerName = "******";
$DBUserName = "********";
$DBPassWord = "*********";
$DBName = "*********";
 
//AD Information
$host = "ldap://**********";
$usersuffix = "************";
$MainURLPrefix = "***********";
?>
Not that I can see

Re: Supposed Redeclaration Error

Posted: Fri Jan 08, 2010 7:26 pm
by Eran
The error clearly states that the function called authenticatead() has been declared more than once. You are either including the same file twice (without using include_once) or have used the same name for separate functions.

Re: Supposed Redeclaration Error

Posted: Fri Jan 08, 2010 7:32 pm
by flying_circus
It doesnt appear that functions.php would do anything if you accessed it directly, as nothing calls the function. I would assume that functions.php is being included by another file?

Have you accidentally included/required functions.php more than once in your code?

Rather than using include() or require(), it is better to use include_once() and require_once().

Edit: Pytrin beat me to it with a ninja post.

Re: Supposed Redeclaration Error

Posted: Mon Jan 11, 2010 12:48 pm
by Bigun
manohoo wrote:Take a look at the contents of config.php. Most likely it will have an include statement to functions.php, where the variable has already been declared.
Looks like you were correct. It was included in the header.php already, so including it in the index.php caused the error, thank you so much.