0

I am dealing with a strange PHP issue.

In my script, I have the following:

$includeRoot = '/home/mydomain/include/';
include_once $includeRoot."table_names.inc";

echo $usersTbl;

The output produces nothing. $usersTbl is defined in table_names.inc as follows:

$usersTbl = 'users';

This code works fine in another script. I tried the following:

Changing include_once to require_once

The problem does not seem to be that the code cannot find the file. If I do the following:

echo (file_get_contents($includeRoot."table_names.inc"));

it actually echoes out the file contents. What am I not seeing here?

Ben Swinburne
  • 25,669
  • 10
  • 69
  • 108
EastsideDev
  • 6,257
  • 9
  • 59
  • 116
  • 1
    (1) why `_once`? does it contain function definitions/is it included earlier? (2) Does the file start with ` – Wrikken Jun 19 '12 at 19:46
  • It's file_get_contents() rather than file_get_content(). Have you looked to see if there are any PHP errors? – Ben Swinburne Jun 19 '12 at 19:48
  • once is because it also includes some other files, so this is to insure that if these other files include some of the same files, there are no complaints about redeclared functions. all the files start with – EastsideDev Jun 19 '12 at 19:49
  • Yes, it's file_get_contents, not file_get_content. Typo on my part when I typed the question. I'm having some trouble locating the PHP error log on the server, and my local log file does not contain clues. – EastsideDev Jun 19 '12 at 19:51

1 Answers1

2

To help debug the issue, try the following:

if( file_exists( $includeRoot . "table_names.inc" ) ) {
    die( "Include file exists!" ) ;
} else {
    die( "Include file does not exist!" ) ;
}

That will at least tell you if the file and filepath actually exist. If the file does exist then the problem may be in your actual include file. If it doesn't exist, then double check your path.

You may also want to make sure error reporting is completely on and dumping to the screen:

error_reporting(E_ALL);
ini_set('display_errors','On'); 
Mike
  • 21
  • 2
  • echo (file_get_contents (includeRoot."table_names.inc")); it echoes the contents of the file. I already tried the if file_exists, and it tells me that it exists. I will double check the error reporting. – EastsideDev Jun 19 '12 at 19:54
  • This is going to sound weird, but the problem went away on its own. The only thing I did was turn error reporting on to ALL. I have been tearing my hair out for the past 8 hours over this problem. I don't have error reporting to ALL, but it's still working. I don't get it. Should I be worrying about viruses on the server? – EastsideDev Jun 19 '12 at 20:02
  • What version of PHP do you have on your server? – Mike Jun 20 '12 at 04:00