Connecting Tech Pros Worldwide Help | Site Map

Accessing Apache environmental variables

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 11:28 AM
Bruce Lehmann
Guest
 
Posts: n/a
Default Accessing Apache environmental variables

Hi,

I've installed Apache (WAMP install) so I can edit and test my web
site on my home computer. In general php code seems to work, but I
can't access Apache variables such as PATH or SCRIPT_NAME.

The code below works perfectly when I upload it to my webhost server.
However, at home, everything processes corectly except the
environmental variables are blank.

Any ideas?

Thanks
Bruce


<html>
<head>
<title>Test3.php</title>
</head>
<body>

<?php
print ( date("g:i A - l, M d, Y"));
$a="hello world";
?>
<br>
<?php
echo '$a = '.$a."\n";
echo '<br>';
echo 'Script Filename: '.$SCRIPT_FILENAME."\n";
echo '<br>';
echo 'Script name : '.$PHP_SELF."\n";
echo '<br>';
echo 'doc_root : '.$DOCUMENT_ROOT."\n";
echo '<br>';
echo 'Path name : '.$PATH."\n";
echo '<br>';
echo 'OSTYPE : '.$OSTYPE."\n";
echo '<br>';
//phpinfo(); //works fine
?>
</body>
</html>

  #2  
Old July 17th, 2005, 11:28 AM
Andy Hassall
Guest
 
Posts: n/a
Default Re: Accessing Apache environmental variables

On 12 Feb 2005 10:19:32 -0800, lehmann@thinkerf.com (Bruce Lehmann) wrote:
[color=blue]
>I've installed Apache (WAMP install) so I can edit and test my web
>site on my home computer. In general php code seems to work, but I
>can't access Apache variables such as PATH or SCRIPT_NAME.
>
>The code below works perfectly when I upload it to my webhost server.
>However, at home, everything processes corectly except the
>environmental variables are blank.
>
> echo 'Script Filename: '.$SCRIPT_FILENAME."\n";
> echo '<br>';
> echo 'Script name : '.$PHP_SELF."\n";[/color]

You're relying on the old, deprecated "register_globals" feature, turned off
by default and staying off for sensible installations of PHP. The values you
want can be found in the $_SERVER superglobal, e.g.
$_SERVER['SCRIPT_FILENAME'].

See the PHP manual:
http://www.php.net/manual/en/languag...s.external.php

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.