Problem with getenv

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

    Problem with getenv

    When I run the following code, I get "Undefined variable: localPath"
    error. I do not understand why? It seems simple enough...but I am new
    to PHP so any help is appreciated.

    I am running PHP 5.2.5 on an XAMPP installation on Win XP/Pro.

    $localpath=gete nv('SCRIPT_NAME ');
    $absolutepath=r ealpath($localP ath);
    // a fix for Windows slashes
    $absolutepath=s tr_replace("\\" ,"/",$absolutepath );
    $docroot=substr ($absolutepath, 0,strpos($absol utepath,$localp ath));


    TIA,
    John
  • Captain Paralytic

    #2
    Re: Problem with getenv

    On 3 Sep, 16:06, john6630 <john6...@hotma il.comwrote:
    When I run the following code, I get "Undefined variable: localPath"
    error. I do not understand why? It seems simple enough...but I am new
    to PHP so any help is appreciated.
    >
    I am running PHP 5.2.5 on an XAMPP installation on Win XP/Pro.
    >
    $localpath=gete nv('SCRIPT_NAME ');
    $absolutepath=r ealpath($localP ath);
    // a fix for Windows slashes
    $absolutepath=s tr_replace("\\" ,"/",$absolutepath );
    $docroot=substr ($absolutepath, 0,strpos($absol utepath,$localp ath));
    >
    TIA,
    John
    Because "localpath" is not the same as "localPath" .

    Look carefully and you will see the difference.

    Comment

    • john6630

      #3
      Re: Problem with getenv

      On Sep 3, 8:20 am, Captain Paralytic <paul_laut...@y ahoo.comwrote:
      On 3 Sep, 16:06, john6630 <john6...@hotma il.comwrote:
      >
      When I run the following code, I get "Undefined variable: localPath"
      error. I do not understand why? It seems simple enough...but I am new
      to PHP so any help is appreciated.
      >
      I am running PHP 5.2.5 on an XAMPP installation on Win XP/Pro.
      >
      $localpath=gete nv('SCRIPT_NAME ');
      $absolutepath=r ealpath($localP ath);
      // a fix for Windows slashes
      $absolutepath=s tr_replace("\\" ,"/",$absolutepath );
      $docroot=substr ($absolutepath, 0,strpos($absol utepath,$localp ath));
      >
      TIA,
      John
      >
      Because "localpath" is not the same as "localPath" .
      >
      Look carefully and you will see the difference.
      Hi Captain,
      I am very embarrased. Case sensitivity is an ongoing battle for me
      since I come from the VB.Net world. Also, the script I copied from a
      web blog has an error in it (just in case anyone is looking at the
      functionality of this, which is to get the document root regardless of
      Apache or IIS as the server). The author forgot the call to basename
      when getting the absolute path. So here is what works:

      $localpath = getenv('SCRIPT_ NAME');
      $absolutepath = realpath(BASENA ME($localpath)) ;
      // a fix for Windows slashes
      $absolutepath = str_replace("\\ ","/",$absolutepath );
      $docroot = substr($absolut epath,0,strpos( $absolutepath,$ localpath));

      Thanks again for the speedy response. This group is fantastic and as a
      newbie, I sincerely appreciate everyone's efforts.

      John

      Comment

      Working...