The PHP code is not executed, but the code is displayed in the browser source code
P粉914731066
2023-08-23 16:04:27
<p>I tried executing some PHP code on the project (using Dreamweaver) but the code didn't run. </p>
<p>When I check the source code, the PHP code appears as HTML tags (I can see it in the source code). Apache runs fine (I'm using XAMPP) and the PHP page opens correctly, but the PHP code is not executed. </p>
<p>Does anyone have any suggestions on what's going on? </p>
<p><strong>Note: </strong>The file has been named <code>filename.php</code></p>
<p><strong>Edit:</strong> Code..:</p>
<pre class="brush:php;toolbar:false;"><?
include_once("/code/configs.php");
?></pre>
php7:
It sounds like there is something wrong with your configuration, you can check the following:
Make sure PHP is installed and running correctly. This may sound silly, but you never know. An easy way to check is to run php -v from the command line and see if version information or any errors are returned.
Make sure the PHP module is listed and uncommented in Apache's httpd.conf, this should look like
LoadModule php5_module "c:/php/php5apache2_2.dll"
in the file. Search forLoadModule php
and make sure it is not preceded by a comment (;
).Make sure that the PHP MIME type is included in Apache's httpd.conf file. This should look like
AddType application/x-httpd-php .php
. This tells Apache to run the.php
file as PHP. Search for AddType and make sure there is an entry for PHP, and that is uncommented.Make sure your file has the
.php
extension, or the extension specified in the MIME definition in point #3, otherwise it will not execute as PHP.Make sure you are not using short tags in PHP files (
), these are not enabled by default on all servers , and their use is discouraged. Use
instead (or if you have code that relies on short tags, use
short_open_tag=On
to enable short tags in php.ini).Make sure you use a URL like
http://localhost/file.php
to access the file through a web server and not through a local filefile://localhost/ www/ file.php
Finally check out the PHP manual for more setup tips.