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.

dotancohen
  • 2,590
  • 2
  • 25
  • 39
  • 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 `` directive or anything? – Zoredache Aug 07 '12 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. –  Aug 07 '12 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 08 '12 at 05: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 08 '12 at 05: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? –  Aug 08 '12 at 08:20
  • Thanks, I put the HTML of the two `phpinfo()` outputs on Pastebin. If you know where I can paste the page, I'll do it. – dotancohen Aug 08 '12 at 09:12

1 Answers1

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
rubo77
  • 2,469
  • 4
  • 34
  • 66
  • 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 '12 at 15:33