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?

4
  • 1
    (1) why _once? does it contain function definitions/is it included earlier? (2) Does the file start with <?php? Commented Jun 19, 2012 at 19:46
  • It's file_get_contents() rather than file_get_content(). Have you looked to see if there are any PHP errors? Commented Jun 19, 2012 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 <?php and they all close with ?> Commented Jun 19, 2012 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. Commented Jun 19, 2012 at 19:51

1 Answer 1

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'); 
Sign up to request clarification or add additional context in comments.

3 Comments

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.
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?
What version of PHP do you have on your server?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.