Using variables defined in an included file (included by another file) in the including file in php
<p>Let's say I have three files that have the following code</p>

<p>File 1: firstfile.php</p>

<pre><code> 
    $dbhost = "localhost";
    $dbname = "mydbname";
    $dbuser = "myuserid";
    $dbpass = "mypass";
    $dblink = mysql_connect($dbhost, $dbuser, $dbpass);
    mysql_select_db($dbname,$dblink);

    $errorlogs = "c:/wamp/www/smstrunk/tmp/weblogs.log";
    $displaycount = 2;
    $querylimit = "LIMIT $displaycount";
    $maximportfilesize = 2097152;

</code></pre>

<p>File 2: secondfile.php</p>

<pre><code>include("firstfile.php");

//Returns the GET/POST parameter value
    function getPassedParam($param){

        if(isset($_POST[$param])) $value = $_POST[$param];
        elseif(isset($_GET[$param])) $value = $_GET[$param];
        else $value = "";

        return $value;
    }
//##########################################

// DB Functions
    function selectSQL($qry, $dblink){

        global $errorlogs;

        $result = mysql_query($qry, $dblink);
        if (!$result) {
            log2File("Invalid query: " . mysql_error());
            return false;
        }
        log2File($qry);

        return $result;
    }

    function updateSQL($qry, $dblink){

        $result = mysql_query($qry, $dblink);
        if (!$result) {
            log2File("Invalid query: " . mysql_error());
            return false;
        }
        log2File($qry);

        return mysql_affected_rows($dblink);
    }

    function insertSQL($qry, $dblink){
            echo $displaycount;
        $result = mysql_query($qry, $dblink);
        if (!$result) {
            log2File("Invalid query: " . mysql_error());
            return false;
        }
        log2File($qry);

        return mysql_insert_id();

    }
//##########################################

//Mailing Functions
    function auto_reg_mail($to, $message){

        $subject = 'Registration Confirmation';
        $headers = 'From: noreply@smstrunk.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion();

        mail($to, $subject, $message, $headers);
    }
//##########################################


//Logging Function
    function log2File($message, $file=NULL){

        global $errorlogs;
        if($file == NULL)$file = $errorlogs;

        $msg = date("Y-m-d H:m:s") . " [" . $_SERVER['PHP_SELF'] . "] $message \n";
        error_log($msg, 3, $file);
    }
//##########################################


// Application Specific Functions
//  1. Get customer id from msisdn
    function getCustID($msisdn, $lowner, $dblink, $alias = ""){

        //Check if msisdn already exists for this user
        $sql = sprintf("SELECT custid, mstatus FROM msisdn WHERE number = '%s' AND owner = '$lowner'", mysql_real_escape_string($msisdn));
        $rsmsisdn = selectSQL($sql, $dblink);

        if($rwmsisdn = mysql_fetch_assoc($rsmsisdn)){
            $custID = $rwmsisdn['custid'];
            $mstatus = $rwmsisdn['mstatus'];
            $sql = sprintf("UPDATE msisdn SET mstatus = 0, alias = '%s' WHERE custID = '$custID'", mysql_real_escape_string($alias));
            updateSQL($sql, $dblink);
        }else{
        // if not insert number
            $sql = sprintf("INSERT INTO msisdn (number, owner, alias) VALUES ('%s', '$lowner', '%s')", $msisdn, mysql_real_escape_string($alias));
            $custID = insertSQL($sql, $dblink);
        }
        return $custID;
    }

?>

</code></pre>

<p>File 3: third.php</p>

<pre><code>include ("secondfile.php");

echo $dblink;

</code></pre>

<p>Why is $dblink giving me undefined variable when I have already defined it in firstfile.php? Does the php compiler/interpreter allow limited levels of include</p>
