Hello guys can anyone tell me how this code works:
<?php
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "pages/include/headertop.php";
include_once($path);
?>
Someone recommended this to me. Since I have trouble with my include files when I transferred it inside the sub-folder/directories:
pages/include/headertop.php
Another problem is that the CSS linked to the include files don't work with the index.php
file since I've transferred the include file to the sub-folders.
These codes below works half-way actually. Problem is that the CSS is not working with it. And if I relink the CSS for the index.php file, the files left in the subfolders gets messed up because of the redirected links.
<?php
include ("pages/include/headertop.php");
include ("pages/include/header.php");
include ("pages/include/nav.php");
?>
By the way, my index.php
file is in the root directory/main folder.
Thanks guys! I really need your help.
I think $_SERVER['DOCUMENT_ROOT'] returns no slash add the end. So your $path is missing a trailing slash.
Maybe this works?
$path .= "/pages/include/headertop.php";
$_SERVER
is an array containing information such as headers, paths, and script locations. it defines the path to a file
and
'DOCUMENT_ROOT' The document root directory under which the current script is executing, as defined in the server's configuration file. detail here
after that you have added the path to your folder
$path .= "pages/include/headertop.php";
and at the end include_once
is added to eliminate duplication of included file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.