Code: Select all
include '/var/www/footer.php';I would show you some of my code but I am in updating my server right now........
files are on a virtual machine and I save them right before I killed my main sever same hard drive i killed
Moderator: General Moderators
Code: Select all
include '/var/www/footer.php';I'm afraid we're not communicating very well. I don't see any need for a database in what we've been discussing. What is it you need to do? You want to have a standard footer for a bunch of web pages, right? That's a common requirement and is typically done using include(). What's the problem? Are these pages part of different web domains? Are these domains being served by the same web server? Perhaps in Virtual Server operation?Vegan wrote:So what can I do, grab the footer from the database?
Yes. Read how include() works: http://php.net/manual/en/function.include.php and read this security explanation: http://phpsec.org/projects/guide/3.html, especially the sentence that says,lang79james wrote:Hey Cal from what your saying is that the include function can use any file on the server. For example lets say I got a file on my desktop I want to use and as long as I use the path to that file I can use it there right?
Of course, one simple solution is to place all modules outside of document root, and this is a good practice. Both include and require can accept a filesystem path, so there's no need to make modules accessible via URL. It is an unnecessary risk.
Code: Select all
<?php
$documentRoot = null;
if (isset($_SERVER['DOCUMENT_ROOT'])) {
$documentRoot = $_SERVER['DOCUMENT_ROOT'];
if (strstr($documentRoot, '/') || strstr($documentRoot, '\\')) {
if (strstr($documentRoot, '/')) {
$documentRoot = str_replace('/', DIRECTORY_SEPARATOR, $documentRoot);
}
elseif (strstr($documentRoot, '\\')) {
$documentRoot = str_replace('\\', DIRECTORY_SEPARATOR, $documentRoot);
}
}
if (preg_match('/[^\\/]{1}\\[^\\/]{1}/', $documentRoot)) {
$documentRoot = preg_replace('/([^\\/]{1})\\([^\\/]{1})/', '\\1DIR_SEP\\2', $documentRoot);
$documentRoot = str_replace('DIR_SEP', '\\\\', $documentRoot);
}
}
else {
/**
* I usually store this file in the Includes folder at the root of my
* virtual host. This can be changed to wherever you store this file.
*
* Example:
* If you store this file in the Application/Settings/DocRoot folder at the
* base of your site, you would change this array to include each of those
* folders.
*
* <code>
* $directories = array(
* 'Application',
* 'Settings',
* 'DocRoot'
* );
* </code>
*/
$directories = array(
'Includes'
);
if (defined('__DIR__')) {
$currentDirectory = __DIR__;
}
else {
$currentDirectory = dirname(__FILE__);
}
$currentDirectory = rtrim($currentDirectory, DIRECTORY_SEPARATOR);
$currentDirectory = $currentDirectory . DIRECTORY_SEPARATOR;
foreach ($directories as $directory) {
$currentDirectory = str_replace(
DIRECTORY_SEPARATOR . $directory . DIRECTORY_SEPARATOR,
DIRECTORY_SEPARATOR,
$currentDirectory
);
}
$currentDirectory = rtrim($currentDirectory, DIRECTORY_SEPARATOR);
}
define('SERVER_DOC_ROOT', $documentRoot);
?>
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Draco Chapter I</title>
<? include "data/head.php"; ?>
<body>
<center>
<table width="700" border=".01" cellspacing="0" cellpadding="0">
<tr>
Code: Select all
<?php include "/var/www/data/footer.php";?>
It's always in the Apache configuration file, httpd.conf. Just search for the line that says "Document Root".Vegan wrote:so to be clear, I need to not look at the web site document root but rather the file system folder.
is there an easier way to identify the web site's document root? This way I can use the same code for many sites that are in various folders.
Yes, that's the common use for include. What is your question?Vegan wrote:The purpose of the include is to eventually compose a document from standard header and footer. This would simplify site development considerably.
Absolute paths?Vegan wrote:I am simply trying to find a generic way to use an include that is relative to the web site folder.