DLR Posted April 1, 2010 Share Posted April 1, 2010 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? Quote Link to comment Share on other sites More sharing options...
ignace Posted April 2, 2010 Share Posted April 2, 2010 if($path)) set_include_path($path); if (is_file($filename)) { //or if (is_file(rtrim($path, '/\\') . DIRECTORY_SEPARATOR . $filename)) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.