0

This file (test.php) runs the PHP info blurb as expected:

<html>
<body>
<?php  
   phpinfo();
?>
</body>
</html>

But this code, also when saved as test.php, generates a blank screen:

<?php
echo "<html><body><?php phpinfo(); ?></body></html>";
?>

The source code here, when reviewed from the browser, shows:

 <html><body><?php phpinfo(); ?></body></html>

...so almost certainly there is something screwy about how I've set up the server to parse things..

I am running a localhost of PHP version 5.6.28 and Apache 2.4 on Windows 10. Other than the newbie setup instructions here, I haven't changed many of the defaults. I do have:

LoadModule php5_module "c:/php/php5apache2_4.dll"
AddType application/x-httpd-php .php

...already in the httpd.conf file.

test.php definitely has a .php extension already, but I did see this idea, so I added this line:

AddHandler php-script .html

...to the httpd.conf file. I also added:

AddType  application/x-httpd-php-source  .phps
AddType text.html .php

that were suggested here: Apache is downloading php files instead of displaying them

Am I missing something obvious?

Update: after monkeying by adding the above lines to the httpd.conf file, test.php actually generates a few unescaped characters?

"; ?>

rather than a totally blank screen, or the expected phpinfo information.

Community
  • 1
  • 1
Suzanne
  • 582
  • 2
  • 11
  • 31
  • 2
    You are echoing out PHP code to output, that output will not be parsed by the PHP engine. – flauntster Dec 12 '16 at 04:05
  • So maybe `echo` isn't what I want -- how can I create code -- in a string, say -- that will be executed? For example, creating forms from code: echo '
    ';
    – Suzanne Dec 12 '16 at 04:25

1 Answers1

1

Going by the comment you posted above, you're looking to concatenate output. Using your example, you could use:

echo '<form id="option-listing-form" method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF']) . '"> ';

Hope this helps :)

flauntster
  • 2,008
  • 13
  • 20