2

Consider this environment:

$ cat .htaccess
AddType application/x-httpd-php .php .html
SetEnv Foo Bar

$ cat test.php
<?php
echo "Hello: ";
echo $_SERVER['Foo'];
echo $_ENV['Foo'];
echo getenv('Foo');
?>

$ cat test.html
<?php
echo "Hello: ";
echo $_SERVER['Foo'];
echo $_ENV['Foo'];
echo getenv('Foo');
?>

This is the output of test.php:

Hello BarBarBar

This is the output of test.html:

Hello 

Why might that be? How might I fix it?

Here is phpinfo.php: http://pastebin.com/rgq7up61

Here is phpinfo.html: http://pastebin.com/VUKFNZ36

If anyone knows where I can host a real webpage instead of just the HTML for one, please let me know and I'll move the content to there. Thanks.

6
  • That is kinda weird. What happens if you put a phpinfo(); in the .html file? Do you see any differences from what you see in a .php file? Are you sure your Apache configuration isn't adjusting the configuration with a <files> directive or anything?
    – Zoredache
    Aug 7, 2012 at 22:06
  • I've tried to reproduce your problem but could not : Output of test.html is same as test.php Hello: BarBar. And I start wondering why one bar is missing.
    – user130370
    Aug 7, 2012 at 22:18
  • Thank, Zoredache. In fact I see many more environment variables for the .html files than for the .php files. However, the Foo variable is only available in the .php files. I don't see any difference in the configuration section, though.
    – dotancohen
    Aug 8, 2012 at 5:42
  • @EricDANNIELOU: It is not unusual that one or two of the methods won't work. I is unusual that .html and .php files will show them differently, though.
    – dotancohen
    Aug 8, 2012 at 5:43
  • I agree. But without being able to reproduce your problem, I won't be able to help a lot. Could you post full apache and php config (change or hide some values if needed). Would you have phpinfo and most softare/os versions?
    – user130370
    Aug 8, 2012 at 8:20

1 Answer 1

1

the difference is visible in the block:

Environment 

there in the html-version all variables are set in the old global form:

$HTTP_HOST, $HTTP_USER_AGENT, etc.

and in the new form too:

$_SERVER["HTTP_HOST"], $_SERVER["HTTP_USER_AGENT"], ...

in the php version they are set only in the new form. it seems like the html-version uses another php.ini.

also i see the variable

$_SERVER["ORIG_SCRIPT_FILENAME"]    ="/var/www/cgi-bin/cgi_wrapper/cgi_wrapper"

maybe the html-file is parsed with the

/etc/php5/cli/php.ini
1
  • Thank you. Due to the AddType declaration in .htaccess I think that both the .html and .php files should be using the same configuration files. I will ask the server admin, though. Thank you Rubo.
    – dotancohen
    Sep 17, 2012 at 15:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .