Jump to content

function for includes does not work on connection to Mysql. Why?


DLR

Recommended Posts

I've read the sticky on headers and the php manual - and am using my version of the recommended way to overcome the "headers already sent" problem. Clearly I'm missing something (obvious?)

 

The following function (based on the example in the php manual) works fine  for file includes but not with file connection to database. Why?

 

function get_include_contents($filename,$path) {
$allowed = array("CEL150.php","signforce_conn-read.php" ); 
if(! in_array($filename,$allowed)) {
		$_SESSION['error_msg'] = "Failed access to file  Error  102-0";

		$_SESSION['error_code'] = 1;
		header("refresh:0;url = ' http://www.celcius-system.com/apps/error.php'");

} else {
    if (is_file($filename)) {
        ob_start();
        if($path) {	
        		set_include_path($path);
        }
        include $filename;
        $contents = ob_get_contents();
        ob_end_clean();
        chdir(dirname($_SERVER['SCRIPT_FILENAME']));
        return $contents;

    } else {
    		$_SESSION['error_msg'] = "Failed access to file  Error  102-1";

			$_SESSION['error_code'] = 1;
			header("refresh:0;url = ' http://www.celcius-system.com/apps/error.php'");
    }
}
}
get_include_contents("CEL150.php","");

this include works fine

 

but this does not

get_include_contents("signforce_conn-read.php","../connect/");

 

The contents of "signforce_conn-read.php" is

$conn = mysql_connect("host", "user", "password") ; 
$db = mysql_select_db("SignForce");

 

If I use the abve code in place of the file "signforce_conn-read.php", it all works fine.

 

Why does the function not work for a connection?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.