Page 2 of 3
Re: include problem
Posted: Wed Sep 22, 2010 4:08 pm
by lang79james
thats would work but what is wrong with
yea it is a lot to type out but i does work like a champ
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

Re: include problem
Posted: Wed Sep 22, 2010 5:18 pm
by califdon
Vegan wrote:So what can I do, grab the footer from the database?
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?
Here are the basics: for any Apache server, there is a Document Root that is specified in httpd.conf. The server and any PHP scripts it runs can include files that are within the file system anywhere in Document Root and its sudirectories. You can specify an includes_path or you can just refer to the appropriate path relative to Document Root each time you specify a file to be included. What include
doesn't do (to the best of my knowledge) is connect with Internet domains, using http protocol. You could probably do that with cURL because that's what it's for. But I didn't get the impression that you were trying to include a file on some other server.
As I understand your requirement, it's just a standard include that you need. You just have to provide a valid file system path so it can find the file.
Re: include problem
Posted: Wed Sep 22, 2010 7:11 pm
by lang79james
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?
Re: include problem
Posted: Wed Sep 22, 2010 8:10 pm
by califdon
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?
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,
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.
Re: include problem
Posted: Wed Sep 22, 2010 11:16 pm
by Vegan
I noticed a fair chunk of PHP code dealing with the some document root construct.
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);
?>
Seems like overkill for a seemingly simple include!
My sites all are folders under /www which is an unorthodox approach but I have used it as its easy to share with SAMBA and backup with gzip etc.
Re: include problem
Posted: Thu Sep 23, 2010 9:05 am
by lang79james
ok dude I got my site kinda back up
I use a header and a footer for all my pages. My header for all my pages is this :
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>
my footer:
Code: Select all
<?php include "/var/www/data/footer.php";?>
This will achieve what you want.....
Re: include problem
Posted: Thu Sep 23, 2010 1:14 pm
by Vegan
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.
Re: include problem
Posted: Thu Sep 23, 2010 1:37 pm
by califdon
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.
It's always in the Apache configuration file, httpd.conf. Just search for the line that says "Document Root".
Re: include problem
Posted: Thu Sep 23, 2010 2:52 pm
by Vegan
All of those paths are in the httpd.conf so I guess I need to parse that file then.
I wonder why an environment variable is not set to allow a program to see what is where.
Re: include problem
Posted: Thu Sep 23, 2010 8:46 pm
by griffinmt
Use include_dir in the php.ini to reference a specific location on the server, and don't put a path in the include statement.
This location can be outside the scope of the actual website files for security.
If the file that you want to include is needed on several servers in a protected internal network, pick one to do your maintenance on, then sync the path contents across the servers on a regular basis.
Re: include problem
Posted: Thu Sep 23, 2010 11:02 pm
by Vegan
The purpose of the include is to eventually compose a document from standard header and footer. This would simplify site development considerably.
Re: include problem
Posted: Thu Sep 23, 2010 11:13 pm
by califdon
Vegan wrote:The purpose of the include is to eventually compose a document from standard header and footer. This would simplify site development considerably.
Yes, that's the common use for include. What is your question?
Re: include problem
Posted: Fri Sep 24, 2010 8:58 am
by Vegan
I am simply trying to find a generic way to use an include that is relative to the web site folder.
Re: include problem
Posted: Fri Sep 24, 2010 12:38 pm
by John Cartwright
Vegan wrote:I am simply trying to find a generic way to use an include that is relative to the web site folder.
Absolute paths?
Re: include problem
Posted: Fri Sep 24, 2010 3:03 pm
by Vegan
Well how is it that phpBB can cope with relative paths OK?