Reputation: 21
I am working with the function require_once but keep getting errors when trying to run the page. Tried looking elsewhere but can't seem to get a precise answer for my problem. My code is:
<?php
require_once(ROOT_DIR . 'Pages/Page.php');
require_once(ROOT_DIR . 'lib/Application/Authentication/namespace.php');
It gives me the following errors:
Notice: Use of undefined constant ROOT_DIR - assumed 'ROOT_DIR' in /opt/lampp/htdocs/myDiary/Pages/LoginPage.php on line 3
Warning: require_once(ROOT_DIRPages/Page.php) [function.require-once]: failed to open stream: No such file or directory in /opt/lampp/htdocs/myDiary/Pages/LoginPage.php on line 3
Fatal error: require_once() [function.require]: Failed opening required 'ROOT_DIRPages/Page.php' (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/myDiary/Pages/LoginPage.php on line 3.
Please explain what my problem is, I haven't been programming for very long.
Upvotes: 1
Views: 1996
Reputation: 74086
It is all clearly stated in the error messages:
ROOT_DIR
is not defined at that position in the script, require_once()
call failing.As a solution make sure to set ROOT_DIR
before using it. See define()
for this.
Upvotes: 1
Reputation: 437
Think this should work
require_once(__ROOT__.'Pages/Page.php');
the useful link is here :
http://php.net/manual/en/function.require-once.php
Upvotes: 0
Reputation: 57322
you are getting this error since you haven't defined the directory
define this by
define('ROOT_DIR', '/path/to/your/scripts/');
Upvotes: 1
Reputation: 1481
Try DOCUMENT_ROOT
<?php
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= 'Pages/Page.php';
include_once($path);
?>
Upvotes: 0
Reputation: 139
You should define ROOT_DIR first.. like so:
define('ROOT_DIR', 'path');
Upvotes: 0
Reputation: 39724
You have to define the constant ROOT_DIR
on top:
define('ROOT_DIR', '/path/to/your/scripts/');
Upvotes: 1