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?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.