GK79
GK79

Reputation: 251

Relative paths in PHP require_once not working

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?

Upvotes: 1

Views: 1565

Answers (1)

Qarib Haider
Qarib Haider

Reputation: 4906

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....

Upvotes: 1

Related Questions