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.

2
  • 2
    You are echoing out PHP code to output, that output will not be parsed by the PHP engine. Commented Dec 12, 2016 at 4: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 '<form id="option-listing-form" method="post" action=" <?php echo htmlspecialchars($_SERVER[&#39;PHP_SELF&#39;]); ?> "> '; Commented Dec 12, 2016 at 4:25

1 Answer 1

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 :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.