1

I have tried the solutions suggested in previous SO answers (PHP - with require_once/include/require, the path is relative to what?)

However, when I try to load my page, it does not work and nothing displays - I get a blank page. The require_once commands are at the top of my page. This is the exact code I'm using:

    <?php 
    $homedir = __DIR__ . '/';
    require_once($homedir.'inc/session.php');
    require_once($homedir.'inc/database_launch.php');
    require_once($homedir.'inc/functions.php');
?>

<!DOCTYPE html><html> ... all other code for the page goes here

When I echo the $homedir variable it correctly echoes the pathname. I've even tried replacing the "require_once" with echo statements and it correctly lists the absolute path to those php pages. I am hosting on BLUEHOST, if that makes a difference.

The individual php files work perfectly fine - I have tested them (individually) on the server and no errors reported in the php files.

What am I doing wrong?

Community
  • 1
  • 1
GK79
  • 241
  • 1
  • 4
  • 17

1 Answers1

1

Try this:

<?php 
ini_set('display_errors', 1);
error_reporting(E_ALL);

$homedir = dirname(__FILE__) . '/';

require_once $homedir . 'inc/session.php';
require_once $homedir . 'inc/database_launch.php';
require_once $homedir . 'inc/functions.php';
?>

And, post your ouput....

Qarib Haider
  • 4,796
  • 5
  • 27
  • 38
  • How odd - this is the error that I get. I checked and (a) the files definitely exist, (b) the files work, (c) the relative paths are correct. Am I making a mistake somewhere? `Warning: require_once(../connections/connection_i.php): failed to open stream: No such file or directory in /home2/dialect7/public_html/inc/database_launch.php on line 3 Fatal error: require_once(): Failed opening required '../connections/connection_i.php' (include_path='.:/usr/php/54/usr/lib64:/usr/php/54/usr/share/pear') in /home2/dialect7/public_html/inc/database_launch.php on line 3` – GK79 Aug 03 '14 at 14:48
  • 1
    So, the error is about the path of file required inside `database_launch.php` .. try including the files inside `database_launch.php` the same way you are doing on `root` i.e. with `dirname(__FILE__)` – Qarib Haider Aug 04 '14 at 06:07
  • Thanks @Syed Qarib - turns out I had a few other "require_once()" scattered in other files that I needed to clean up in the same way. – GK79 Aug 04 '14 at 12:55