Reputation: 1
I have
public_html/dir/dir1/1.php and public_html/dir/dir2/2.php
how to include 1.php into 2.php?
DETAILS: I have 2 file as public_html/projectplay/functions/functions.php And public_html/projectplay/includes/header.php
And also, public_html/projectplay/includes/header_pc.php public_html/projectplay/includes/header_mob.php
In header.php, I must include functions.php I tried bellow code
<?php
require '../functions/functions.php';
if ( $detect->isMobile() ) {
include 'header_mob.php';
}
else {
include 'header_pc.php';
}
?>
ANd my public_html/projectplay/index.php is here
<?php require_once 'functions/functions.php'; ?>
<!DOCTYPE html>
<?php include 'includes/header.php';?>
Dummy Dummy Dymmy
<?php include 'includes/footer.php';?>
And public_html/projectplay/includes/footer.php is
But it output an error on index.php
Warning: require(../functions/functions.php): failed to open stream: No such file or directory in /home/epdroidc/public_html/projectplay/includes/header.php on line 2
Warning: require(../functions/functions.php): failed to open stream: No such file or directory in /home/epdroidc/public_html/projectplay/includes/header.php on line 2
Fatal error: require(): Failed opening required '../functions/functions.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/epdroidc/public_html/projectplay/includes/header.php on line 2
Where is my problem? I am new in php.
Upvotes: 0
Views: 61
Reputation:
in php2:
require_once('../dir1/php1.php');
or
require_once($_SERVER['DOCUMENT_ROOT'].'/public_html/dir/dir1/php1.php');
Upvotes: 0
Reputation: 1562
Use absolute instead of relative paths. See this question for reference.
Note that it seems that in index.php you already require functions/functions.php
. Your application logic occurs to be a bit chaotic.
Upvotes: 0