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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul

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

    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('includ e_path','.:..') ;
    ...
    require_once('H TML/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('includ e_path','.:..') ; see the directory above it? If not,
    how can I change it to see the directory above it?

    Any ideas are MUCH appreciated!


  • Steve

    #2
    Re: where can ini_set('includ e_path','.:..') ; see?


    "Paul" <lof@invalid.co mwrote in message
    news:8h9Ph.2813 2$Wc.13392@bign ews3.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('includ e_path','.:..') ;
    | ...
    | require_once('H TML/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($_SERVE R['PHP_SELF']);
    $parsedUri .= substr($parsedU ri, -1) != '/' ? '/' : '';
    $relativeUri = str_replace('/', '', $parsedUri);
    $relativePath = strlen($parsedU ri) - strlen($relativ eUri) - 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('includ e_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...becau se 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('includ e_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;
    $securityEnable d = true;
    require_once 'relative.path. php';
    require_once $relativePath . 'site.cfg.php';
    require_once site::$includeD irectory . 'head.inc.php';
    ?>

    notice the use of the static site::$includeD irectory 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('displa y_errors' , true );
    ini_set('error_ reporting' , E_ALL & E_ERROR & E_WARNING );
    ini_set('max_ex ecution_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::initializ e();

    site::$rootDire ctory = $rootDirectory;
    site::$uri = 'http' . ($securityEnabl ed ? 's' : '') .
    '://' . $_SERVER['HTTP_HOST'];
    site::$uri = 'http://' . $_SERVER['HTTP_HOST'] . '/';
    site::$uploadBa seDirectory = site::$rootDire ctory . 'data/';
    site::$mailDrop Directory = site::$rootDire ctory . 'data/mail/';
    site::$adminEma il = Web Site Administrator <no.one@example .com>';

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

    site::$currentP age = basename($_SERV ER['PHP_SELF']);

    site::$classDir ectory = site::$rootDire ctory . 'classes/';
    site::$cssDirec tory = site::$uri . 'css/';
    site::$host = 'tccc';
    site::$errorLog File = site::$rootDire ctory . site::$host .
    '.errors.log';
    site::$fontDire ctory = '/var/www/fonts/';
    site::$homePage = site::$uri . 'index.php';
    site::$htdocsDi rectory = site::$rootDire ctory;
    site::$imagesDi rectory = site::$uri . 'images/';
    site::$includeD irectory = site::$rootDire ctory . 'inc/';
    site::$jscriptD irectory = site::$uri . 'jscript/';
    site::$logo = site::$imagesDi rectory . 'logo.jpg';
    site::$popUpAtt ributes = '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::$includeD irectory . 'functions.inc. php';

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

    $enableContextM enu = true;

    // site database information

    require_once site::$classDir ectory . 'db.class.php';
    try
    {
    db::connect('lo calhost', '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::$adminEma il;
    $emailNotify['CC'] = site::$adminEma il;
    $emailNotify['BCC'] = '';

    // get relative font sizes for the browser

    require_once site::$classDir ectory . 'browser.class. php';

    $browser = browser::getIns tance();
    $sessionFonts = $browser->getFonts();

    // user interaction

    require_once site::$classDir ectory . 'user.class.php ';

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

    if ($logOut)
    {
    user::reset();
    session_unset() ;
    session_destroy ();
    header('locatio n:' . 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 $htdocsDirector y = '';
    public static $imagesDirector y = '';
    public static $includeDirecto ry = '';
    public static $jscriptDirecto ry = '';
    public static $lastSecurityCo de = '';
    public static $logo = '';
    public static $mailDropDirect ory = '';
    public static $popUpAttribute s = '';
    public static $rootDirectory = '';
    public static $securityCode = '';
    public static $title = '';
    public static $uploadBaseDire ctory = '';
    public static $uri = '';

    private function __clone(){}

    private function __construct(){}

    private static function getSecurityCode ()
    {
    $alphabet = '2347ACEFHJKLMN PRTWXYZ'; // removed those that
    look too similar
    $alphabetLength = strlen($alphabe t) - 1;
    self::$security Code = '';
    for ($i = 0; $i < 6; $i++)
    {
    self::$security Code .= $alphabet[mt_rand(0, $alphabetLength )];
    }
    $_SESSION['securityCode'] = self::$security Code;
    if (!self::$lastSe curityCode){ self::$lastSecu rityCode =
    self::$security Code; }
    }

    public static function initialize()
    {
    self::$lastSecu rityCode = $_SESSION['securityCode'];
    self::getSecuri tyCode();
    }
    }
    ?>

    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



    Comment

    • Toby A Inkster

      #3
      Re: where can ini_set('includ e_path','.:..') ; see?

      Paul wrote:
      /site/html/Common.php
      Lowercase
      require_once('H TML/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!

      Comment

      • Steve

        #4
        Re: where can ini_set('includ e_path','.:..') ; see?

        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!


        Comment

        • Paul

          #5
          Re: where can ini_set('includ e_path','.:..') ; see?

          "Steve" <no.one@example .comwrote in message
          news:utbPh.4149 $%f3.4061@newsf e04.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!


          Comment

          • Steve

            #6
            Re: where can ini_set('includ e_path','.:..') ; see?


            "Paul" <lof@invalid.co mwrote in message
            news:FOdPh.1230 7$5i7.11576@big news4.bellsouth .net...
            | "Steve" <no.one@example .comwrote in message
            | news:utbPh.4149 $%f3.4061@newsf e04.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.


            Comment

            • Paul

              #7
              Re: where can ini_set('includ e_path','.:..') ; see?

              "Steve" <no.one@example .comwrote in message
              news:iVePh.263$ EN4.91@newsfe12 .lga...
              >
              "Paul" <lof@invalid.co mwrote in message
              news:FOdPh.1230 7$5i7.11576@big news4.bellsouth .net...
              | "Steve" <no.one@example .comwrote in message
              | news:utbPh.4149 $%f3.4061@newsf e04.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.


              Comment

              • Steve

                #8
                Re: where can ini_set('includ e_path','.:..') ; see?

                | 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


                Comment

                • Paul

                  #9
                  Re: where can ini_set('includ e_path','.:..') ; see?

                  "Steve" <no.one@example .comwrote in message
                  news:ttaPh.10$E N4.8@newsfe12.l ga...
                  >
                  "Paul" <lof@invalid.co mwrote in message
                  news:8h9Ph.2813 2$Wc.13392@bign ews3.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('includ e_path','.:..') ;
                  | ...
                  | require_once('H TML/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($_SERVE R['PHP_SELF']);
                  $parsedUri .= substr($parsedU ri, -1) != '/' ? '/' : '';
                  $relativeUri = str_replace('/', '', $parsedUri);
                  $relativePath = strlen($parsedU ri) - strlen($relativ eUri) - 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('includ e_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...becau se 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('includ e_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;
                  $securityEnable d = true;
                  require_once 'relative.path. php';
                  require_once $relativePath . 'site.cfg.php';
                  require_once site::$includeD irectory . 'head.inc.php';
                  ?>
                  >
                  notice the use of the static site::$includeD irectory 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('displa y_errors' , true );
                  ini_set('error_ reporting' , E_ALL & E_ERROR & E_WARNING );
                  ini_set('max_ex ecution_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::initializ e();
                  >
                  site::$rootDire ctory = $rootDirectory;
                  site::$uri = 'http' . ($securityEnabl ed ? 's' : '') .
                  '://' . $_SERVER['HTTP_HOST'];
                  site::$uri = 'http://' . $_SERVER['HTTP_HOST'] . '/';
                  site::$uploadBa seDirectory = site::$rootDire ctory . 'data/';
                  site::$mailDrop Directory = site::$rootDire ctory . 'data/mail/';
                  site::$adminEma il = Web Site Administrator
                  <no.one@example .com>';
                  >
                  site::$title = 'SAMPLE WEB SITE;
                  site::$descript ion = 'A SIMPLE PROVING GROUND';
                  >
                  site::$currentP age = basename($_SERV ER['PHP_SELF']);
                  >
                  site::$classDir ectory = site::$rootDire ctory . 'classes/';
                  site::$cssDirec tory = site::$uri . 'css/';
                  site::$host = 'tccc';
                  site::$errorLog File = site::$rootDire ctory . site::$host .
                  '.errors.log';
                  site::$fontDire ctory = '/var/www/fonts/';
                  site::$homePage = site::$uri . 'index.php';
                  site::$htdocsDi rectory = site::$rootDire ctory;
                  site::$imagesDi rectory = site::$uri . 'images/';
                  site::$includeD irectory = site::$rootDire ctory . 'inc/';
                  site::$jscriptD irectory = site::$uri . 'jscript/';
                  site::$logo = site::$imagesDi rectory . 'logo.jpg';
                  site::$popUpAtt ributes = '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::$includeD irectory . 'functions.inc. php';
                  >
                  // source code security (disables 'view source' from right-click)
                  >
                  $enableContextM enu = true;
                  >
                  // site database information
                  >
                  require_once site::$classDir ectory . 'db.class.php';
                  try
                  {
                  db::connect('lo calhost', '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::$adminEma il;
                  $emailNotify['CC'] = site::$adminEma il;
                  $emailNotify['BCC'] = '';
                  >
                  // get relative font sizes for the browser
                  >
                  require_once site::$classDir ectory . 'browser.class. php';
                  >
                  $browser = browser::getIns tance();
                  $sessionFonts = $browser->getFonts();
                  >
                  // user interaction
                  >
                  require_once site::$classDir ectory . 'user.class.php ';
                  >
                  $logOut = isset($_REQUEST['logOut']);
                  >
                  if ($logOut)
                  {
                  user::reset();
                  session_unset() ;
                  session_destroy ();
                  header('locatio n:' . 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 $htdocsDirector y = '';
                  public static $imagesDirector y = '';
                  public static $includeDirecto ry = '';
                  public static $jscriptDirecto ry = '';
                  public static $lastSecurityCo de = '';
                  public static $logo = '';
                  public static $mailDropDirect ory = '';
                  public static $popUpAttribute s = '';
                  public static $rootDirectory = '';
                  public static $securityCode = '';
                  public static $title = '';
                  public static $uploadBaseDire ctory = '';
                  public static $uri = '';
                  >
                  private function __clone(){}
                  >
                  private function __construct(){}
                  >
                  private static function getSecurityCode ()
                  {
                  $alphabet = '2347ACEFHJKLMN PRTWXYZ'; // removed those that
                  look too similar
                  $alphabetLength = strlen($alphabe t) - 1;
                  self::$security Code = '';
                  for ($i = 0; $i < 6; $i++)
                  {
                  self::$security Code .= $alphabet[mt_rand(0, $alphabetLength )];
                  }
                  $_SESSION['securityCode'] = self::$security Code;
                  if (!self::$lastSe curityCode){ self::$lastSecu rityCode =
                  self::$security Code; }
                  }
                  >
                  public static function initialize()
                  {
                  self::$lastSecu rityCode = $_SESSION['securityCode'];
                  self::getSecuri tyCode();
                  }
                  }
                  ?>
                  >
                  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_fi le?
                  That would save a lot of time.


                  Comment

                  • Paul

                    #10
                    Re: where can ini_set('includ e_path','.:..') ; see?

                    "Steve" <no.one@example .comwrote in message
                    news:ttaPh.10$E N4.8@newsfe12.l ga...
                    >
                    "Paul" <lof@invalid.co mwrote in message
                    news:8h9Ph.2813 2$Wc.13392@bign ews3.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('includ e_path','.:..') ;
                    | ...
                    | require_once('H TML/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($_SERVE R['PHP_SELF']);
                    $parsedUri .= substr($parsedU ri, -1) != '/' ? '/' : '';
                    $relativeUri = str_replace('/', '', $parsedUri);
                    $relativePath = strlen($parsedU ri) - strlen($relativ eUri) - 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('includ e_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...becau se 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('includ e_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;
                    $securityEnable d = true;
                    require_once 'relative.path. php';
                    require_once $relativePath . 'site.cfg.php';
                    require_once site::$includeD irectory . 'head.inc.php';
                    ?>
                    >
                    notice the use of the static site::$includeD irectory 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('displa y_errors' , true );
                    ini_set('error_ reporting' , E_ALL & E_ERROR & E_WARNING );
                    ini_set('max_ex ecution_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::initializ e();
                    >
                    site::$rootDire ctory = $rootDirectory;
                    site::$uri = 'http' . ($securityEnabl ed ? 's' : '') .
                    '://' . $_SERVER['HTTP_HOST'];
                    site::$uri = 'http://' . $_SERVER['HTTP_HOST'] . '/';
                    site::$uploadBa seDirectory = site::$rootDire ctory . 'data/';
                    site::$mailDrop Directory = site::$rootDire ctory . 'data/mail/';
                    site::$adminEma il = Web Site Administrator
                    <no.one@example .com>';
                    >
                    site::$title = 'SAMPLE WEB SITE;
                    site::$descript ion = 'A SIMPLE PROVING GROUND';
                    >
                    site::$currentP age = basename($_SERV ER['PHP_SELF']);
                    >
                    site::$classDir ectory = site::$rootDire ctory . 'classes/';
                    site::$cssDirec tory = site::$uri . 'css/';
                    site::$host = 'tccc';
                    site::$errorLog File = site::$rootDire ctory . site::$host .
                    '.errors.log';
                    site::$fontDire ctory = '/var/www/fonts/';
                    site::$homePage = site::$uri . 'index.php';
                    site::$htdocsDi rectory = site::$rootDire ctory;
                    site::$imagesDi rectory = site::$uri . 'images/';
                    site::$includeD irectory = site::$rootDire ctory . 'inc/';
                    site::$jscriptD irectory = site::$uri . 'jscript/';
                    site::$logo = site::$imagesDi rectory . 'logo.jpg';
                    site::$popUpAtt ributes = '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::$includeD irectory . 'functions.inc. php';
                    >
                    // source code security (disables 'view source' from right-click)
                    >
                    $enableContextM enu = true;
                    >
                    // site database information
                    >
                    require_once site::$classDir ectory . 'db.class.php';
                    try
                    {
                    db::connect('lo calhost', '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::$adminEma il;
                    $emailNotify['CC'] = site::$adminEma il;
                    $emailNotify['BCC'] = '';
                    >
                    // get relative font sizes for the browser
                    >
                    require_once site::$classDir ectory . 'browser.class. php';
                    >
                    $browser = browser::getIns tance();
                    $sessionFonts = $browser->getFonts();
                    >
                    // user interaction
                    >
                    require_once site::$classDir ectory . 'user.class.php ';
                    >
                    $logOut = isset($_REQUEST['logOut']);
                    >
                    if ($logOut)
                    {
                    user::reset();
                    session_unset() ;
                    session_destroy ();
                    header('locatio n:' . 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 $htdocsDirector y = '';
                    public static $imagesDirector y = '';
                    public static $includeDirecto ry = '';
                    public static $jscriptDirecto ry = '';
                    public static $lastSecurityCo de = '';
                    public static $logo = '';
                    public static $mailDropDirect ory = '';
                    public static $popUpAttribute s = '';
                    public static $rootDirectory = '';
                    public static $securityCode = '';
                    public static $title = '';
                    public static $uploadBaseDire ctory = '';
                    public static $uri = '';
                    >
                    private function __clone(){}
                    >
                    private function __construct(){}
                    >
                    private static function getSecurityCode ()
                    {
                    $alphabet = '2347ACEFHJKLMN PRTWXYZ'; // removed those that
                    look too similar
                    $alphabetLength = strlen($alphabe t) - 1;
                    self::$security Code = '';
                    for ($i = 0; $i < 6; $i++)
                    {
                    self::$security Code .= $alphabet[mt_rand(0, $alphabetLength )];
                    }
                    $_SESSION['securityCode'] = self::$security Code;
                    if (!self::$lastSe curityCode){ self::$lastSecu rityCode =
                    self::$security Code; }
                    }
                    >
                    public static function initialize()
                    {
                    self::$lastSecu rityCode = $_SESSION['securityCode'];
                    self::getSecuri tyCode();
                    }
                    }
                    ?>
                    >
                    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\Qu ickForm\element .php on line 22"

                    Line 22 is:
                    require_once('H TML/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!


                    Comment

                    • Steve

                      #11
                      Re: where can ini_set('includ e_path','.:..') ; see?

                      | Steve:
                      |
                      | Can I just put 'relative.path. php' in php.ini for the auto_prepend_fi le?
                      | 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).


                      Comment

                      • Steve

                        #12
                        Re: where can ini_set('includ e_path','.:..') ; see?

                        | 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\Qu ickForm\element .php on line 22"
                        |
                        | Line 22 is:
                        | require_once('H TML/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.p hp. 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?


                        Comment

                        • Paul

                          #13
                          Re: where can ini_set('includ e_path','.:..') ; see?

                          >| 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\Qu ickForm\element .php on line 22"
                          |
                          | Line 22 is:
                          | require_once('H TML/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.p hp. 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\HTM L\QuickForm\ele ment.php on line 22"

                          Despite the auto_prepend_fi le 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.p hp 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!


                          Comment

                          • Paul

                            #14
                            Re: where can ini_set('includ e_path','.:..') ; see?

                            In addition to previous post:

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

                            echo $relativePath;

                            exit;

                            And this is the error it throws:

                            C:\site\inc\rel ative.path.php
                            Notice: Undefined variable: relativePath in
                            C:\site\HTML\Qu ickForm\element .php on line 3

                            So, the relative path is being included.


                            Comment

                            • Steve

                              #15
                              Re: where can ini_set('includ e_path','.:..') ; see?


                              "Paul" <lof@invalid.co mwrote in message
                              news:CSbQh.3341 4$68.16068@bign ews8.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\Qu ickForm\element .php on line
                              22"
                              | |
                              | | Line 22 is:
                              | | require_once('H TML/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.p hp. 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\HTM L\QuickForm\ele ment.php on line 22"
                              |
                              | Despite the auto_prepend_fi le 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:

                              sitepagessomedi r

                              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.p hp 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?


                              Comment

                              Working...