You are here: Re: where can ini_set('include_path','.:..'); see? « All PHP « IT news, forums, messages
Re: where can ini_set('include_path','.:..'); see?

Posted by Paul on 04/02/07 17:23

"Steve" <no.one@example.com> wrote in message
news:ttaPh.10$EN4.8@newsfe12.lga...
>
> "Paul" <lof@invalid.com> wrote in message
> news:8h9Ph.28132$Wc.13392@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.one@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!

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация