Jump to content

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


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?

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.