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

Problem with getenv

P: n/a
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=getenv('SCRIPT_NAME');
$absolutepath=realpath($localPath);
// a fix for Windows slashes
$absolutepath=str_replace("\\","/",$absolutepath);
$docroot=substr($absolutepath,0,strpos($absolutepa th,$localpath));
TIA,
John
Sep 3 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 3 Sep, 16:06, john6630 <john6...@hotmail.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=getenv('SCRIPT_NAME');
$absolutepath=realpath($localPath);
// a fix for Windows slashes
$absolutepath=str_replace("\\","/",$absolutepath);
$docroot=substr($absolutepath,0,strpos($absolutepa th,$localpath));

TIA,
John
Because "localpath" is not the same as "localPath".

Look carefully and you will see the difference.
Sep 3 '08 #2

P: n/a
On Sep 3, 8:20 am, Captain Paralytic <paul_laut...@yahoo.comwrote:
On 3 Sep, 16:06, john6630 <john6...@hotmail.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=getenv('SCRIPT_NAME');
$absolutepath=realpath($localPath);
// a fix for Windows slashes
$absolutepath=str_replace("\\","/",$absolutepath);
$docroot=substr($absolutepath,0,strpos($absolutepa th,$localpath));
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(BASENAME($localpath));
// a fix for Windows slashes
$absolutepath = str_replace("\\","/",$absolutepath);
$docroot = substr($absolutepath,0,strpos($absolutepath,$local path));

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

John
Sep 3 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.