Supposed Redeclaration Error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Supposed Redeclaration Error

Post 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;
}
?>
 
User avatar
manohoo
Forum Contributor
Posts: 201
Joined: Wed Dec 23, 2009 12:28 pm

Re: Supposed Redeclaration Error

Post 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.
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Re: Supposed Redeclaration Error

Post by Bigun »

Code: Select all

<?php
//SQL Information
$MSSQLServerName = "******";
$DBUserName = "********";
$DBPassWord = "*********";
$DBName = "*********";
 
//AD Information
$host = "ldap://**********";
$usersuffix = "************";
$MainURLPrefix = "***********";
?>
Not that I can see
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Supposed Redeclaration Error

Post 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.
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Supposed Redeclaration Error

Post 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.
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Re: Supposed Redeclaration Error

Post 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.
Post Reply