By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,306 Members | 1,621 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,306 IT Pros & Developers. It's quick & easy.

where can ini_set('include_path','.:..'); see?

P: n/a
I am taking over an existing app and having trouble understanding their
references.

They have encapsulated Pear packages in the directory structure like:
/site
/site/html/Pear.php
/site/html/Sigma.php
/site/html/Common.php
/site/html/Quickform.php
/site/html/Quickform/
/site/Mail/mail.php
/pages/page1.php

At the top of /site/html/Quickform.php they put:
ini_set('include_path','.:..');
...
require_once('HTML/Common.php');

And it throws an error trying to find 'HTML/Common.php' which is in the same
directory but referenced from the directory above it.

I have tried every configuration in the apache conf file and changing the
code itself.

So, can ini_set('include_path','.:..'); see the directory above it? If not,
how can I change it to see the directory above it?

Any ideas are MUCH appreciated!
Mar 30 '07 #1
Share this Question
Share on Google+
24 Replies


P: n/a

"Paul" <lo*@invalid.comwrote in message
news:8h******************@bignews3.bellsouth.net.. .
|I am taking over an existing app and having trouble understanding their
| references.
|
| They have encapsulated Pear packages in the directory structure like:
| /site
| /site/html/Pear.php
| /site/html/Sigma.php
| /site/html/Common.php
| /site/html/Quickform.php
| /site/html/Quickform/
| /site/Mail/mail.php
| /pages/page1.php
|
| At the top of /site/html/Quickform.php they put:
| ini_set('include_path','.:..');
| ...
| require_once('HTML/Common.php');

dude paul, i could have sworn i gave you a fix for this! just edit the php
ini file. you need to create a file called 'relative.path.php'. and put it
in your php include path (that you are soon to quick fucking around with
using ini_set). that file has this code in it:

<?
$parsedUri = dirname($_SERVER['PHP_SELF']);
$parsedUri .= substr($parsedUri, -1) != '/' ? '/' : '';
$relativeUri = str_replace('/', '', $parsedUri);
$relativePath = strlen($parsedUri) - strlen($relativeUri) - 1;
if ($relativePath < 0){ $relativePath = 0; }
$relativePath = str_repeat('../', $relativePath);
if (!$relativePath){ $relativePath = './'; }
?>

then i'd put this at the beginning of *EVERY* php file your site has:

<?
require_once 'relative.path.php';
?>

i'd remove every instance of ini_set('include_path', '.:..') that i saw.
that is a horrible way to get the desired effect and the programmer should
summarily be drawn and quartered. this method requires that the file
*always* be a relative distance for what you're including. it could also
severly fuck up a script that includes another and then tries to include
another...because each is setting the include_path! further, it doesn't
allow you to reuse the known relativity to call other folders for inclusion
like classes, common functions, whatever. this scenario requires *all*
includes to be in one folder. not very flexible, is it!

you'll notice that 'relative.path.php' creates a variable called
$relativePath. you'll also notice that it is compatible with all versions of
php...such that you can use it on a server that runs both php 4 or php 5.
the variable points to the root of your web application. once you know that,
you can merrily jump about. anyway, your code would become:

<?
require_once 'relative.path.php';
require_once $relativePath . 'HTML/Common.php';
?>

now it doesn't matter where your script is put in your directory structure.
as it is, your code doesn't work because ini_set('include_path','.:..')
isn't setting a valid path. the best solution would be to further abstract
your directory structure. here's what i put at the top of *EVERY* script of
my own:

<?
$pageTitle = "Welcome";
$fullHeader = true;
$securityEnabled = true;
require_once 'relative.path.php';
require_once $relativePath . 'site.cfg.php';
require_once site::$includeDirectory . 'head.inc.php';
?>

notice the use of the static site::$includeDirectory interface?
'site.cfg.php' configures the path. if i had a common header that should be
shown on a page (as i have in the above ficticious page), i could now
include it no matter where either the header nor the including page existed.
get the idea?

i have a configuration script called 'site.cfg.php'. it sets paths into
variables. so, when you implement the site, you can put your files all over
the gawd damned place and manage it all in one spot. the rest of your
scripts couldn't care less how crazy you go. they reference variables.
here's my site.cfg.php script:

<?
ini_set('display_errors' , true );
ini_set('error_reporting' , E_ALL & E_ERROR & E_WARNING );
ini_set('max_execution_time' , 0 );
ini_set('memory_limit' , '100M' );

session_start();

// site basic information

$rootDirectory = '/var/www/html/dev/';

require_once $rootDirectory . 'classes/site.class.php';

site::initialize();

site::$rootDirectory = $rootDirectory;
site::$uri = 'http' . ($securityEnabled ? 's' : '') .
'://' . $_SERVER['HTTP_HOST'];
site::$uri = 'http://' . $_SERVER['HTTP_HOST'] . '/';
site::$uploadBaseDirectory = site::$rootDirectory . 'data/';
site::$mailDropDirectory = site::$rootDirectory . 'data/mail/';
site::$adminEmail = Web Site Administrator <no****@example.com>';

site::$title = 'SAMPLE WEB SITE;
site::$description = 'A SIMPLE PROVING GROUND';

site::$currentPage = basename($_SERVER['PHP_SELF']);

site::$classDirectory = site::$rootDirectory . 'classes/';
site::$cssDirectory = site::$uri . 'css/';
site::$host = 'tccc';
site::$errorLogFile = site::$rootDirectory . site::$host .
'.errors.log';
site::$fontDirectory = '/var/www/fonts/';
site::$homePage = site::$uri . 'index.php';
site::$htdocsDirectory = site::$rootDirectory;
site::$imagesDirectory = site::$uri . 'images/';
site::$includeDirectory = site::$rootDirectory . 'inc/';
site::$jscriptDirectory = site::$uri . 'jscript/';
site::$logo = site::$imagesDirectory . 'logo.jpg';
site::$popUpAttributes = 'addressbar=0, channelmode=0, dependent=1,
directories=0, fullscreen=0, location=0, menubar=0, resizable=1, status=0,
titlebar=0, toolbar=0';

// common php functionality

require_once site::$includeDirectory . 'functions.inc.php';

// source code security (disables 'view source' from right-click)

$enableContextMenu = true;

// site database information

require_once site::$classDirectory . 'db.class.php';
try
{
db::connect('localhost', 'user', 'password', 'db');
} catch (exception $ex) {
print "<pre>\r\n" . $ex->getMessage() . "\r\n" .
' in file ' . $ex->getFile() . "\r\n" .
' on line ' . $ex->getLine() . "\r\n" .
'</pre>';
}

// site notifcations

$emailNotify['TO'] = site::$adminEmail;
$emailNotify['CC'] = site::$adminEmail;
$emailNotify['BCC'] = '';

// get relative font sizes for the browser

require_once site::$classDirectory . 'browser.class.php';

$browser = browser::getInstance();
$sessionFonts = $browser->getFonts();

// user interaction

require_once site::$classDirectory . 'user.class.php';

$logOut = isset($_REQUEST['logOut']);

if ($logOut)
{
user::reset();
session_unset();
session_destroy();
header('location:' . site::$uri);
exit;
}
?>

i'm using php 5, so if you are using a prior version, just adjust the static
interfaces on the site class appropriately. don't know what i mean? post
that as another question here. here is my site object:

<?
class site
{
public static $adminEmail = '';
public static $classDirectory = '';
public static $cssDirectory = '';
public static $currentPage = '';
public static $description = '';
public static $errorLogFile = '';
public static $fontDirectory = '';
public static $homePage = '';
public static $host = '';
public static $htdocsDirectory = '';
public static $imagesDirectory = '';
public static $includeDirectory = '';
public static $jscriptDirectory = '';
public static $lastSecurityCode = '';
public static $logo = '';
public static $mailDropDirectory = '';
public static $popUpAttributes = '';
public static $rootDirectory = '';
public static $securityCode = '';
public static $title = '';
public static $uploadBaseDirectory = '';
public static $uri = '';

private function __clone(){}

private function __construct(){}

private static function getSecurityCode()
{
$alphabet = '2347ACEFHJKLMNPRTWXYZ'; // removed those that
look too similar
$alphabetLength = strlen($alphabet) - 1;
self::$securityCode = '';
for ($i = 0; $i < 6; $i++)
{
self::$securityCode .= $alphabet[mt_rand(0, $alphabetLength)];
}
$_SESSION['securityCode'] = self::$securityCode;
if (!self::$lastSecurityCode){ self::$lastSecurityCode =
self::$securityCode; }
}

public static function initialize()
{
self::$lastSecurityCode = $_SESSION['securityCode'];
self::getSecurityCode();
}
}
?>

the other classes mentioned in the site.cfg.php are one's that i won't get
in to. i included this one so you could see how i set my important paths and
how easy this all is to maintain. it is light-weight, manageable, scaleable,
and highly flexible.

hth,

me

Mar 30 '07 #2

P: n/a
Paul wrote:
/site/html/Common.php
Lowercase
require_once('HTML/Common.php');
Uppercase

OS?

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Mar 30 '07 #3

P: n/a
btw, don't top post.

your post shows 3.30.2007 12.38 PM.
my response (which is the correct time) was 3.30.2007 10.57 AM.

man, i've got to start checking that before i feed the idiots!
Mar 30 '07 #4

P: n/a
"Steve" <no****@example.comwrote in message
news:ut*****************@newsfe04.lga...
btw, don't top post.

your post shows 3.30.2007 12.38 PM.
my response (which is the correct time) was 3.30.2007 10.57 AM.

man, i've got to start checking that before i feed the idiots!
I can't remember if it was you I was explaining this to or not, but I do not
purposely manipulate the time on my machine, When I post it is the correct
time for my time zone.

I do appreciate your help!
Mar 30 '07 #5

P: n/a

"Paul" <lo*@invalid.comwrote in message
news:FO*******************@bignews4.bellsouth.net. ..
| "Steve" <no****@example.comwrote in message
| news:ut*****************@newsfe04.lga...
| btw, don't top post.
| >
| your post shows 3.30.2007 12.38 PM.
| my response (which is the correct time) was 3.30.2007 10.57 AM.
| >
| man, i've got to start checking that before i feed the idiots!
|
| I can't remember if it was you I was explaining this to or not, but I do
not
| purposely manipulate the time on my machine, When I post it is the
correct
| time for my time zone.

as i've said, the clock on YOUR computer IS OFF ... no matter the
timezone!!! fix it, or i'll plonk you.

| I do appreciate your help!

not a problem. why did you completely ignore the help the FIRST time i
explained this all to you? it was the exact same problem and the exact same
solution. if you have nothing better to do, i sure have.

fix your clock.
Mar 30 '07 #6

P: n/a
"Steve" <no****@example.comwrote in message
news:iV**************@newsfe12.lga...
>
"Paul" <lo*@invalid.comwrote in message
news:FO*******************@bignews4.bellsouth.net. ..
| "Steve" <no****@example.comwrote in message
| news:ut*****************@newsfe04.lga...
| btw, don't top post.
| >
| your post shows 3.30.2007 12.38 PM.
| my response (which is the correct time) was 3.30.2007 10.57 AM.
| >
| man, i've got to start checking that before i feed the idiots!
|
| I can't remember if it was you I was explaining this to or not, but I do
not
| purposely manipulate the time on my machine, When I post it is the
correct
| time for my time zone.

as i've said, the clock on YOUR computer IS OFF ... no matter the
timezone!!! fix it, or i'll plonk you.

| I do appreciate your help!

not a problem. why did you completely ignore the help the FIRST time i
explained this all to you? it was the exact same problem and the exact
same
solution. if you have nothing better to do, i sure have.

fix your clock.
You were right - I was in the wrong time zone - my huge apologies. I just
set this laptop up and thought I had done that.
Mar 30 '07 #7

P: n/a
| fix your clock.
|
| You were right - I was in the wrong time zone - my huge apologies. I just
| set this laptop up and thought I had done that.

no big since i believe you that it wasn't intentional.

let me know if the scripts i posted are hard to work out...otherwise, the
simple suggestion of using $relativePath (first two scripts posted) should
solve your immediate problem.

cheers
Mar 31 '07 #8

P: n/a
"Steve" <no****@example.comwrote in message
news:tt************@newsfe12.lga...
>
"Paul" <lo*@invalid.comwrote in message
news:8h******************@bignews3.bellsouth.net.. .
|I am taking over an existing app and having trouble understanding their
| references.
|
| They have encapsulated Pear packages in the directory structure like:
| /site
| /site/html/Pear.php
| /site/html/Sigma.php
| /site/html/Common.php
| /site/html/Quickform.php
| /site/html/Quickform/
| /site/Mail/mail.php
| /pages/page1.php
|
| At the top of /site/html/Quickform.php they put:
| ini_set('include_path','.:..');
| ...
| require_once('HTML/Common.php');

dude paul, i could have sworn i gave you a fix for this! just edit the php
ini file. you need to create a file called 'relative.path.php'. and put it
in your php include path (that you are soon to quick fucking around with
using ini_set). that file has this code in it:

<?
$parsedUri = dirname($_SERVER['PHP_SELF']);
$parsedUri .= substr($parsedUri, -1) != '/' ? '/' : '';
$relativeUri = str_replace('/', '', $parsedUri);
$relativePath = strlen($parsedUri) - strlen($relativeUri) - 1;
if ($relativePath < 0){ $relativePath = 0; }
$relativePath = str_repeat('../', $relativePath);
if (!$relativePath){ $relativePath = './'; }
?>

then i'd put this at the beginning of *EVERY* php file your site has:

<?
require_once 'relative.path.php';
?>

i'd remove every instance of ini_set('include_path', '.:..') that i saw.
that is a horrible way to get the desired effect and the programmer should
summarily be drawn and quartered. this method requires that the file
*always* be a relative distance for what you're including. it could also
severly fuck up a script that includes another and then tries to include
another...because each is setting the include_path! further, it doesn't
allow you to reuse the known relativity to call other folders for
inclusion
like classes, common functions, whatever. this scenario requires *all*
includes to be in one folder. not very flexible, is it!

you'll notice that 'relative.path.php' creates a variable called
$relativePath. you'll also notice that it is compatible with all versions
of
php...such that you can use it on a server that runs both php 4 or php 5.
the variable points to the root of your web application. once you know
that,
you can merrily jump about. anyway, your code would become:

<?
require_once 'relative.path.php';
require_once $relativePath . 'HTML/Common.php';
?>

now it doesn't matter where your script is put in your directory
structure.
as it is, your code doesn't work because ini_set('include_path','.:..')
isn't setting a valid path. the best solution would be to further abstract
your directory structure. here's what i put at the top of *EVERY* script
of
my own:

<?
$pageTitle = "Welcome";
$fullHeader = true;
$securityEnabled = true;
require_once 'relative.path.php';
require_once $relativePath . 'site.cfg.php';
require_once site::$includeDirectory . 'head.inc.php';
?>

notice the use of the static site::$includeDirectory interface?
'site.cfg.php' configures the path. if i had a common header that should
be
shown on a page (as i have in the above ficticious page), i could now
include it no matter where either the header nor the including page
existed.
get the idea?

i have a configuration script called 'site.cfg.php'. it sets paths into
variables. so, when you implement the site, you can put your files all
over
the gawd damned place and manage it all in one spot. the rest of your
scripts couldn't care less how crazy you go. they reference variables.
here's my site.cfg.php script:

<?
ini_set('display_errors' , true );
ini_set('error_reporting' , E_ALL & E_ERROR & E_WARNING );
ini_set('max_execution_time' , 0 );
ini_set('memory_limit' , '100M' );

session_start();

// site basic information

$rootDirectory = '/var/www/html/dev/';

require_once $rootDirectory . 'classes/site.class.php';

site::initialize();

site::$rootDirectory = $rootDirectory;
site::$uri = 'http' . ($securityEnabled ? 's' : '') .
'://' . $_SERVER['HTTP_HOST'];
site::$uri = 'http://' . $_SERVER['HTTP_HOST'] . '/';
site::$uploadBaseDirectory = site::$rootDirectory . 'data/';
site::$mailDropDirectory = site::$rootDirectory . 'data/mail/';
site::$adminEmail = Web Site Administrator
<no****@example.com>';

site::$title = 'SAMPLE WEB SITE;
site::$description = 'A SIMPLE PROVING GROUND';

site::$currentPage = basename($_SERVER['PHP_SELF']);

site::$classDirectory = site::$rootDirectory . 'classes/';
site::$cssDirectory = site::$uri . 'css/';
site::$host = 'tccc';
site::$errorLogFile = site::$rootDirectory . site::$host .
'.errors.log';
site::$fontDirectory = '/var/www/fonts/';
site::$homePage = site::$uri . 'index.php';
site::$htdocsDirectory = site::$rootDirectory;
site::$imagesDirectory = site::$uri . 'images/';
site::$includeDirectory = site::$rootDirectory . 'inc/';
site::$jscriptDirectory = site::$uri . 'jscript/';
site::$logo = site::$imagesDirectory . 'logo.jpg';
site::$popUpAttributes = 'addressbar=0, channelmode=0, dependent=1,
directories=0, fullscreen=0, location=0, menubar=0, resizable=1, status=0,
titlebar=0, toolbar=0';

// common php functionality

require_once site::$includeDirectory . 'functions.inc.php';

// source code security (disables 'view source' from right-click)

$enableContextMenu = true;

// site database information

require_once site::$classDirectory . 'db.class.php';
try
{
db::connect('localhost', 'user', 'password', 'db');
} catch (exception $ex) {
print "<pre>\r\n" . $ex->getMessage() . "\r\n" .
' in file ' . $ex->getFile() . "\r\n" .
' on line ' . $ex->getLine() . "\r\n" .
'</pre>';
}

// site notifcations

$emailNotify['TO'] = site::$adminEmail;
$emailNotify['CC'] = site::$adminEmail;
$emailNotify['BCC'] = '';

// get relative font sizes for the browser

require_once site::$classDirectory . 'browser.class.php';

$browser = browser::getInstance();
$sessionFonts = $browser->getFonts();

// user interaction

require_once site::$classDirectory . 'user.class.php';

$logOut = isset($_REQUEST['logOut']);

if ($logOut)
{
user::reset();
session_unset();
session_destroy();
header('location:' . site::$uri);
exit;
}
?>

i'm using php 5, so if you are using a prior version, just adjust the
static
interfaces on the site class appropriately. don't know what i mean? post
that as another question here. here is my site object:

<?
class site
{
public static $adminEmail = '';
public static $classDirectory = '';
public static $cssDirectory = '';
public static $currentPage = '';
public static $description = '';
public static $errorLogFile = '';
public static $fontDirectory = '';
public static $homePage = '';
public static $host = '';
public static $htdocsDirectory = '';
public static $imagesDirectory = '';
public static $includeDirectory = '';
public static $jscriptDirectory = '';
public static $lastSecurityCode = '';
public static $logo = '';
public static $mailDropDirectory = '';
public static $popUpAttributes = '';
public static $rootDirectory = '';
public static $securityCode = '';
public static $title = '';
public static $uploadBaseDirectory = '';
public static $uri = '';

private function __clone(){}

private function __construct(){}

private static function getSecurityCode()
{
$alphabet = '2347ACEFHJKLMNPRTWXYZ'; // removed those that
look too similar
$alphabetLength = strlen($alphabet) - 1;
self::$securityCode = '';
for ($i = 0; $i < 6; $i++)
{
self::$securityCode .= $alphabet[mt_rand(0, $alphabetLength)];
}
$_SESSION['securityCode'] = self::$securityCode;
if (!self::$lastSecurityCode){ self::$lastSecurityCode =
self::$securityCode; }
}

public static function initialize()
{
self::$lastSecurityCode = $_SESSION['securityCode'];
self::getSecurityCode();
}
}
?>

the other classes mentioned in the site.cfg.php are one's that i won't get
in to. i included this one so you could see how i set my important paths
and
how easy this all is to maintain. it is light-weight, manageable,
scaleable,
and highly flexible.

hth,

me
Steve:

Can I just put 'relative.path.php' in php.ini for the auto_prepend_file?
That would save a lot of time.
Apr 2 '07 #9

P: n/a
"Steve" <no****@example.comwrote in message
news:tt************@newsfe12.lga...
>
"Paul" <lo*@invalid.comwrote in message
news:8h******************@bignews3.bellsouth.net.. .
|I am taking over an existing app and having trouble understanding their
| references.
|
| They have encapsulated Pear packages in the directory structure like:
| /site
| /site/html/Pear.php
| /site/html/Sigma.php
| /site/html/Common.php
| /site/html/Quickform.php
| /site/html/Quickform/
| /site/Mail/mail.php
| /pages/page1.php
|
| At the top of /site/html/Quickform.php they put:
| ini_set('include_path','.:..');
| ...
| require_once('HTML/Common.php');

dude paul, i could have sworn i gave you a fix for this! just edit the php
ini file. you need to create a file called 'relative.path.php'. and put it
in your php include path (that you are soon to quick fucking around with
using ini_set). that file has this code in it:

<?
$parsedUri = dirname($_SERVER['PHP_SELF']);
$parsedUri .= substr($parsedUri, -1) != '/' ? '/' : '';
$relativeUri = str_replace('/', '', $parsedUri);
$relativePath = strlen($parsedUri) - strlen($relativeUri) - 1;
if ($relativePath < 0){ $relativePath = 0; }
$relativePath = str_repeat('../', $relativePath);
if (!$relativePath){ $relativePath = './'; }
?>

then i'd put this at the beginning of *EVERY* php file your site has:

<?
require_once 'relative.path.php';
?>

i'd remove every instance of ini_set('include_path', '.:..') that i saw.
that is a horrible way to get the desired effect and the programmer should
summarily be drawn and quartered. this method requires that the file
*always* be a relative distance for what you're including. it could also
severly fuck up a script that includes another and then tries to include
another...because each is setting the include_path! further, it doesn't
allow you to reuse the known relativity to call other folders for
inclusion
like classes, common functions, whatever. this scenario requires *all*
includes to be in one folder. not very flexible, is it!

you'll notice that 'relative.path.php' creates a variable called
$relativePath. you'll also notice that it is compatible with all versions
of
php...such that you can use it on a server that runs both php 4 or php 5.
the variable points to the root of your web application. once you know
that,
you can merrily jump about. anyway, your code would become:

<?
require_once 'relative.path.php';
require_once $relativePath . 'HTML/Common.php';
?>

now it doesn't matter where your script is put in your directory
structure.
as it is, your code doesn't work because ini_set('include_path','.:..')
isn't setting a valid path. the best solution would be to further abstract
your directory structure. here's what i put at the top of *EVERY* script
of
my own:

<?
$pageTitle = "Welcome";
$fullHeader = true;
$securityEnabled = true;
require_once 'relative.path.php';
require_once $relativePath . 'site.cfg.php';
require_once site::$includeDirectory . 'head.inc.php';
?>

notice the use of the static site::$includeDirectory interface?
'site.cfg.php' configures the path. if i had a common header that should
be
shown on a page (as i have in the above ficticious page), i could now
include it no matter where either the header nor the including page
existed.
get the idea?

i have a configuration script called 'site.cfg.php'. it sets paths into
variables. so, when you implement the site, you can put your files all
over
the gawd damned place and manage it all in one spot. the rest of your
scripts couldn't care less how crazy you go. they reference variables.
here's my site.cfg.php script:

<?
ini_set('display_errors' , true );
ini_set('error_reporting' , E_ALL & E_ERROR & E_WARNING );
ini_set('max_execution_time' , 0 );
ini_set('memory_limit' , '100M' );

session_start();

// site basic information

$rootDirectory = '/var/www/html/dev/';

require_once $rootDirectory . 'classes/site.class.php';

site::initialize();

site::$rootDirectory = $rootDirectory;
site::$uri = 'http' . ($securityEnabled ? 's' : '') .
'://' . $_SERVER['HTTP_HOST'];
site::$uri = 'http://' . $_SERVER['HTTP_HOST'] . '/';
site::$uploadBaseDirectory = site::$rootDirectory . 'data/';
site::$mailDropDirectory = site::$rootDirectory . 'data/mail/';
site::$adminEmail = Web Site Administrator
<no****@example.com>';

site::$title = 'SAMPLE WEB SITE;
site::$description = 'A SIMPLE PROVING GROUND';

site::$currentPage = basename($_SERVER['PHP_SELF']);

site::$classDirectory = site::$rootDirectory . 'classes/';
site::$cssDirectory = site::$uri . 'css/';
site::$host = 'tccc';
site::$errorLogFile = site::$rootDirectory . site::$host .
'.errors.log';
site::$fontDirectory = '/var/www/fonts/';
site::$homePage = site::$uri . 'index.php';
site::$htdocsDirectory = site::$rootDirectory;
site::$imagesDirectory = site::$uri . 'images/';
site::$includeDirectory = site::$rootDirectory . 'inc/';
site::$jscriptDirectory = site::$uri . 'jscript/';
site::$logo = site::$imagesDirectory . 'logo.jpg';
site::$popUpAttributes = 'addressbar=0, channelmode=0, dependent=1,
directories=0, fullscreen=0, location=0, menubar=0, resizable=1, status=0,
titlebar=0, toolbar=0';

// common php functionality

require_once site::$includeDirectory . 'functions.inc.php';

// source code security (disables 'view source' from right-click)

$enableContextMenu = true;

// site database information

require_once site::$classDirectory . 'db.class.php';
try
{
db::connect('localhost', 'user', 'password', 'db');
} catch (exception $ex) {
print "<pre>\r\n" . $ex->getMessage() . "\r\n" .
' in file ' . $ex->getFile() . "\r\n" .
' on line ' . $ex->getLine() . "\r\n" .
'</pre>';
}

// site notifcations

$emailNotify['TO'] = site::$adminEmail;
$emailNotify['CC'] = site::$adminEmail;
$emailNotify['BCC'] = '';

// get relative font sizes for the browser

require_once site::$classDirectory . 'browser.class.php';

$browser = browser::getInstance();
$sessionFonts = $browser->getFonts();

// user interaction

require_once site::$classDirectory . 'user.class.php';

$logOut = isset($_REQUEST['logOut']);

if ($logOut)
{
user::reset();
session_unset();
session_destroy();
header('location:' . site::$uri);
exit;
}
?>

i'm using php 5, so if you are using a prior version, just adjust the
static
interfaces on the site class appropriately. don't know what i mean? post
that as another question here. here is my site object:

<?
class site
{
public static $adminEmail = '';
public static $classDirectory = '';
public static $cssDirectory = '';
public static $currentPage = '';
public static $description = '';
public static $errorLogFile = '';
public static $fontDirectory = '';
public static $homePage = '';
public static $host = '';
public static $htdocsDirectory = '';
public static $imagesDirectory = '';
public static $includeDirectory = '';
public static $jscriptDirectory = '';
public static $lastSecurityCode = '';
public static $logo = '';
public static $mailDropDirectory = '';
public static $popUpAttributes = '';
public static $rootDirectory = '';
public static $securityCode = '';
public static $title = '';
public static $uploadBaseDirectory = '';
public static $uri = '';

private function __clone(){}

private function __construct(){}

private static function getSecurityCode()
{
$alphabet = '2347ACEFHJKLMNPRTWXYZ'; // removed those that
look too similar
$alphabetLength = strlen($alphabet) - 1;
self::$securityCode = '';
for ($i = 0; $i < 6; $i++)
{
self::$securityCode .= $alphabet[mt_rand(0, $alphabetLength)];
}
$_SESSION['securityCode'] = self::$securityCode;
if (!self::$lastSecurityCode){ self::$lastSecurityCode =
self::$securityCode; }
}

public static function initialize()
{
self::$lastSecurityCode = $_SESSION['securityCode'];
self::getSecurityCode();
}
}
?>

the other classes mentioned in the site.cfg.php are one's that i won't get
in to. i included this one so you could see how i set my important paths
and
how easy this all is to maintain. it is light-weight, manageable,
scaleable,
and highly flexible.

hth,

me
Steve - this seems to be working on files EXCEPT those deeper in
directories, for example, files within:
/site/html/Quickform/

throw the error:
"Warning: main(HTML/Common.php) [function.main]: failed to open stream: No
such file or directory in C:\site\HTML\QuickForm\element.php on line 22"

Line 22 is:
require_once('HTML/Common.php');

There are also directoryies under /site/html/Quickform/, like
/site/html/Quickform/Renderer/
/site/html/Quickform/Rules/

So I need it work for those as well.

Any ideas? I think I/you/we am very close!
Apr 2 '07 #10

P: n/a
| Steve:
|
| Can I just put 'relative.path.php' in php.ini for the auto_prepend_file?
| That would save a lot of time.

i don't see why not other than you may not have access to the php.ini file
on every system/host...whereas you usually do have access to the inc
directory. it's not a bad idea though.

you may also want to think about chaning the $relativePath variable to a
$_SERVER variable. not a big deal either, but it makes it seem more of an
application/server product rather than some abstract variable that comes
from apparently nowhere (from other developer's perspectives who may later
work on the code as well).
Apr 2 '07 #11

P: n/a
| Steve - this seems to be working on files EXCEPT those deeper in
| directories, for example, files within:
| /site/html/Quickform/
|
| throw the error:
| "Warning: main(HTML/Common.php) [function.main]: failed to open stream: No
| such file or directory in C:\site\HTML\QuickForm\element.php on line 22"
|
| Line 22 is:
| require_once('HTML/Common.php');
|
| There are also directoryies under /site/html/Quickform/, like
| /site/html/Quickform/Renderer/
| /site/html/Quickform/Rules/
|
| So I need it work for those as well.
|
| Any ideas? I think I/you/we am very close!

yes. as someone else pointed out, most systems on which you place this web
application are case-sensitive. as a rule for myself, i always lower-case
all directory and file names. as you have probably guessed by now, i do
things very methodically...so much so that i type using lower case. ;^) i
only use proper casing when i do formal writing.

anyway, your problem now stems on the fact that you are requiring
HTML/Common.php, yet on your file system, you only have html/common.php.
make sense? in addition, your line 22 should be:

require_once $relativePath . 'html/common.php'

in order to make use of relative.path.php. also, i am assuming that your web
root is /site.

have you also thought about using something similar to site.cfg.php in order
to define your directory structure literally, such that your scripts refer
to paths via variables?
Apr 2 '07 #12

P: n/a
>| Steve - this seems to be working on files EXCEPT those deeper in
| directories, for example, files within:
| /site/html/Quickform/
|
| throw the error:
| "Warning: main(HTML/Common.php) [function.main]: failed to open stream:
No
| such file or directory in C:\site\HTML\QuickForm\element.php on line 22"
|
| Line 22 is:
| require_once('HTML/Common.php');
|
| There are also directoryies under /site/html/Quickform/, like
| /site/html/Quickform/Renderer/
| /site/html/Quickform/Rules/
|
| So I need it work for those as well.
|
| Any ideas? I think I/you/we am very close!

yes. as someone else pointed out, most systems on which you place this web
application are case-sensitive. as a rule for myself, i always lower-case
all directory and file names. as you have probably guessed by now, i do
things very methodically...so much so that i type using lower case. ;^) i
only use proper casing when i do formal writing.

anyway, your problem now stems on the fact that you are requiring
HTML/Common.php, yet on your file system, you only have html/common.php.
make sense? in addition, your line 22 should be:

require_once $relativePath . 'html/common.php'

in order to make use of relative.path.php. also, i am assuming that your
web
root is /site.

have you also thought about using something similar to site.cfg.php in
order
to define your directory structure literally, such that your scripts refer
to paths via variables?
I can actually put the following in /site/pages/page1.php and it works fine:
require_once $relativePath.'HTML/Common.php';

But when put in:
/site/html/Quickform/Element.php

it throws:
"Notice: Undefined variable: relativePath in
C:\...\site\HTML\QuickForm\element.php on line 22"

Despite the auto_prepend_file working in that file - I have checked.

I think I need help making your code snippet go deeper in the directory
settings. Instead of going up one level, it needs to go up another level
but that will vary depending on where the file. Does that make sense?

Here's what's happening. When you open:
/site/pages/page1.php

it calls:
/site/HTML/Quickform.php properly

That file calls:
/site/HTML/Quickform/elements.php, and THAT is where the error iccurs. The
%relativepath is not defined in /site/HTML/Quickform/elements.php despite
the relative.path.php being included in that file. I can only conclude that
the dept to which the directory structure is being walked up or down is not
enough.

Any ideas? Your help is MUCH appreciated!
Apr 2 '07 #13

P: n/a
In addition to previous post:

I add this to the top of site/HTML/Quickform/element.php
echo ini_get('auto_prepend_file');

echo $relativePath;

exit;

And this is the error it throws:

C:\site\inc\relative.path.php
Notice: Undefined variable: relativePath in
C:\site\HTML\QuickForm\element.php on line 3

So, the relative path is being included.
Apr 2 '07 #14

P: n/a

"Paul" <lo*@invalid.comwrote in message
news:CS******************@bignews8.bellsouth.net.. .
|>| Steve - this seems to be working on files EXCEPT those deeper in
| | directories, for example, files within:
| | /site/html/Quickform/
| |
| | throw the error:
| | "Warning: main(HTML/Common.php) [function.main]: failed to open
stream:
| No
| | such file or directory in C:\site\HTML\QuickForm\element.php on line
22"
| |
| | Line 22 is:
| | require_once('HTML/Common.php');
| |
| | There are also directoryies under /site/html/Quickform/, like
| | /site/html/Quickform/Renderer/
| | /site/html/Quickform/Rules/
| |
| | So I need it work for those as well.
| |
| | Any ideas? I think I/you/we am very close!
| >
| yes. as someone else pointed out, most systems on which you place this
web
| application are case-sensitive. as a rule for myself, i always
lower-case
| all directory and file names. as you have probably guessed by now, i do
| things very methodically...so much so that i type using lower case. ;^)
i
| only use proper casing when i do formal writing.
| >
| anyway, your problem now stems on the fact that you are requiring
| HTML/Common.php, yet on your file system, you only have html/common.php.
| make sense? in addition, your line 22 should be:
| >
| require_once $relativePath . 'html/common.php'
| >
| in order to make use of relative.path.php. also, i am assuming that your
| web
| root is /site.
| >
| have you also thought about using something similar to site.cfg.php in
| order
| to define your directory structure literally, such that your scripts
refer
| to paths via variables?
|
| I can actually put the following in /site/pages/page1.php and it works
fine:
| require_once $relativePath.'HTML/Common.php';
|
| But when put in:
| /site/html/Quickform/Element.php
|
| it throws:
| "Notice: Undefined variable: relativePath in
| C:\...\site\HTML\QuickForm\element.php on line 22"
|
| Despite the auto_prepend_file working in that file - I have checked.
|
| I think I need help making your code snippet go deeper in the directory
| settings. Instead of going up one level, it needs to go up another level
| but that will vary depending on where the file. Does that make sense?

it already DOES all that. it looks for '/' and replaces it with ''. the
difference between the original string and the replaced result (the path
minus the '/'s) is the number of directories to the current directory.
$relativePath simply creates a string by repeating '../' with the number of
replacements made. so:

/site/pages/somedir

would result in:

sitepagessomedir

that's three dir's shorter.

str_repeat would produce:

'../../../'

and if you were in 'somedir' and wanted to get to the root dir from the
command-line, that's exactly what you'd type. cd ../../../

same with php.
| Here's what's happening. When you open:
| /site/pages/page1.php
|
| it calls:
| /site/HTML/Quickform.php properly
|
| That file calls:
| /site/HTML/Quickform/elements.php, and THAT is where the error iccurs.
The
| %relativepath is not defined in /site/HTML/Quickform/elements.php despite
| the relative.path.php being included in that file. I can only conclude
that
| the dept to which the directory structure is being walked up or down is
not
| enough.
|
| Any ideas? Your help is MUCH appreciated!

debug. why not go to a directory that is deeply nested, create a new php
script like this:

<?
echo '<pre>' . $relativePath . '</pre>';
?>

does it produce the correct path for that directory to your root?
Apr 2 '07 #15

P: n/a

"Paul" <lo*@invalid.comwrote in message
news:qW******************@bignews8.bellsouth.net.. .
| In addition to previous post:
|
| I add this to the top of site/HTML/Quickform/element.php
| echo ini_get('auto_prepend_file');
|
| echo $relativePath;
|
| exit;
|
| And this is the error it throws:
|
| C:\site\inc\relative.path.php
| Notice: Undefined variable: relativePath in
| C:\site\HTML\QuickForm\element.php on line 3
|
| So, the relative path is being included.

so, NO, it is NOT being included. 'NOTICE: UNDEFINED VARIABLE: relativePath
....'

i'd forget about using the auto_prepend_file until you got it working AT ALL
first. get fancy only AFTER.
Apr 2 '07 #16

P: n/a
| <?
| echo '<pre>' . $relativePath . '</pre>';
| ?>
|
| does it produce the correct path for that directory to your root?

and that's only IF you get relative.path.php to work as an
auto_prepend_file. otherwise, do as i have suggested and just plop the
script in php's include path. in that case, your debugging script would look
like:

<?
require_once 'relative.path.php';
echo '<pre>' . $relativePath . '</pre>';
?>
Apr 2 '07 #17

P: n/a
lol. i was just looking on the net to see if there were any unknows (to me)
that would cause auto prepend file not to work. it doesn't seem like it but,
i came across this link:

http://www.webmasterworld.com/forum88/421.htm

notice the example is trying to accomplish the same thing we are? it's
funny! you can also see they explode to find out the number of directories
where i use str_replace. i assume that if he were going to finish the code,
it would involve, you guessed it, str_repeat - his would be
str_repeat('../', count($hisExplosion).

i don't know why, after so many years of development going into php, why
there is NOT a $_SERVER variable for the current path, even if it is a
relative one.
Apr 2 '07 #18

P: n/a
| I add this to the top of site/HTML/Quickform/element.php
| echo ini_get('auto_prepend_file');
|
| echo $relativePath;
|
| exit;
|
| And this is the error it throws:
|
| C:\site\inc\relative.path.php
| Notice: Undefined variable: relativePath in
| C:\site\HTML\QuickForm\element.php on line 3
|
| So, the relative path is being included.

so, NO, it is NOT being included. 'NOTICE: UNDEFINED VARIABLE:
relativePath
...'

i'd forget about using the auto_prepend_file until you got it working AT
ALL
first. get fancy only AFTER.
It actually is auto-prepending to
/site/pages/page1.php

but not prepending to
/site/html/Quickform/elements.php

When I add:
echo ini_get('auto_prepend_file');
echo "rel path: ".$relativePath;
exit;

to elements.php, it displays:
C:\site\inc\relative.path.php
Notice: Undefined variable: relativePath in
C:\site\HTML\QuickForm\element.php on line 3
rel path:

So it appears to be "seeing" where the relative.path.php is but not
executing it. It does see and execute the script in /site/pages/page1.php
Apr 2 '07 #19

P: n/a
| It actually is auto-prepending to
| /site/pages/page1.php
|
| but not prepending to
| /site/html/Quickform/elements.php
|
| When I add:
| echo ini_get('auto_prepend_file');
| echo "rel path: ".$relativePath;
| exit;
|
| to elements.php, it displays:
| C:\site\inc\relative.path.php
| Notice: Undefined variable: relativePath in
| C:\site\HTML\QuickForm\element.php on line 3
| rel path:
|
| So it appears to be "seeing" where the relative.path.php is but not
| executing it. It does see and execute the script in /site/pages/page1.php

hmmm. i don't know what to say, other than don't use auto prepend file just
yet. put relative.path.php in your include path. then require_once
'relative.path.php' in your /site/html/quickform/element.php script...THEN
run the same test. while you're at it, add another echo for debugging:

echo ini_get('include_path');

make sure that relative.path.php, for this test, is in your include
path...which may or may not actually be c:/site/inc/

let me know how that one goes.
Apr 2 '07 #20

P: n/a
I add this to the botoom of relative.path.php:
echo "######## $relativePath ########";
I add the following to /site/HTML/Quickform/elements.php:
require_once('relative.path.php');
echo ini_get('include_path');
echo "rel path: ".$relativePath;
exit;

and it displays:
######## ../ ########
..;C:\site\inc
Notice: Undefined variable: relativePath in
C:\site\HTML\QuickForm\element.php on line 4
rel path:

So, it IS accessing the relative.path.php file, but not executing it. If I
add the code into that file, it works fine. The file relative.path.php is
in c:\site\inc directory.
Apr 2 '07 #21

P: n/a
To Steve and everyone else who helped. I finally got it working.

Many many thanks to all!!
Apr 2 '07 #22

P: n/a

"Paul" <lo*@invalid.comwrote in message
news:7Z******************@bignews8.bellsouth.net.. .
|I add this to the botoom of relative.path.php:
| echo "######## $relativePath ########";
|
|
| I add the following to /site/HTML/Quickform/elements.php:
| require_once('relative.path.php');
| echo ini_get('include_path');
| echo "rel path: ".$relativePath;
| exit;
|
| and it displays:
| ######## ../ ########
| .;C:\site\inc
| Notice: Undefined variable: relativePath in
| C:\site\HTML\QuickForm\element.php on line 4
| rel path:
|
| So, it IS accessing the relative.path.php file, but not executing it. If
I
| add the code into that file, it works fine. The file relative.path.php is
| in c:\site\inc directory.

but it only works if the raw code in relative.path.php is pasted directly
into the elements.php page? is c:/site/inc in the php.ini as one of the
include_paths? have you tried storing $relativePath as
$_SERVER['RELATIVE_PATH'] in the site.cfg.php and then echoing out the first
test again to see if the results are more favorable? you'd just change the
"rel path: " . $_SERVER['RELATIVE_PATH'] line for the test.

let me know how it goes. btw, are you still running this test in prepend
mode? it may be that the prepended relative.path.php is not being parsed by
php which would explain why you could require it in prepend mode yet still
not have $relativePath defined.
Apr 3 '07 #23

P: n/a
got it working!

Many thanks for your help!!
Apr 3 '07 #24

P: n/a

"Paul" <lo*@invalid.comwrote in message
news:Zy******************@bignews6.bellsouth.net.. .
| got it working!
|
| Many thanks for your help!!
no problem.
Apr 3 '07 #25

This discussion thread is closed

Replies have been disabled for this discussion.