Jump to content

functions works for some calls not others - why? How to overcome?


DLR

Recommended Posts

I'm trying to code using includes for efficiency - but also need to be mindful of the "headers already sent" problem. So I'm using the model suggested in the php manual  - function "get_include_contents()". It works fine for some calls to the function - but not others.

Here is the function

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

		$_SESSION['error_code'] = 1;				
		header("Location: ../apps/error.php");

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

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

			$_SESSION['error_code'] = 1;
			header("Location : ../apps/../apps/error.php");
			exit();
 	 }
}
}

 

Now this call works fine

get_include_contents("","CEL150.php");

 

and so does this

get_include_contents("../connect/",$_SESSION['conn-read']);

 

but this does not

get_include_contents("../client_info/",$_SESSION['header']);

 

But if I use

 

include("../client_info/" . $_SESSION['header']); 

instead of the function it works fine (but obviously I get header already sent messages).

 

The whole idea of using the function is to avoid the problems of "headers already sent".

But why oh why does it not work?

This call for help after countless ours of problem solving - actually no soloutions, just innumerable options.

Any suggestions?

Thanks

David

Thanks for the suggestion - but it does not work either. The file - $_SESSION['header'] - just contains html code - see below - does the problem somehow lie with this file?

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>SignForce job management area</title>
<link rel="stylesheet" type="text/css" href="../client_info/signforce.css">
</head>
<body>
<table width="100%" border="0" class="header">
<tr>
<td><img src="../client_info/SignForce-70.jpg" width="175" height="38" alt="SignForce logo">
	<br>
	Custom made, world-class signs & signage, delivered & installed anywhere in Southern Africa</td>

<td class="logout">
     <a href="../index.php"><img src="../logout.jpg" width="91" height="33" alt="logout" border="0"></a>
</td>

</tr>
</table>

well assuming $_SESSION variables contain filenames right? not the actual header, which is supposed to be in a file..

 

<?php

$allowed = array("CEL150.php","celcius_conn.php",$_SESSION['header'],$_SESSION['conn-read'] );



function get_include_contents($fullPath) {
global $allowed;
$filename = pathinfo($fullPath, PATHINFO_FILENAME);
$pathname = pathinfo($fullPath, PATHINFO_DIRNAME);

if (! in_array($filename, $allowed))
{
	$_SESSION['error_msg'] = "Failed access to file  Error  201-0";
	$_SESSION['error_code'] = 1;
	header("Location: ../apps/error.php");
} else {
	if (is_file($pathname.$filename)) {
		$cwd      = pathinfo($_SERVER['SERVER_NAME'] .  $_SERVER['PHP_SELF'], PATHINFO_DIRNAME);
		$contents = file_get_contents('http://' . $cwd . $filename);
       } else {
             $_SESSION['error_msg'] = "Failed access to file  Error  201-1";

            $_SESSION['error_code'] = 1;
            header("Location : ../apps/../apps/error.php");
            exit();
        }
   }
}

 

 

something like that will do a file_get_contents pretty much simulating what a user would see in his browser if he used this url. helps?

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.