本文介绍了PHP代码没有被执行,但代码显示在浏览器源代码中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在项目上执行一些 PHP 代码(使用 Dreamweaver),但代码没有运行.

I'm trying to execute some PHP code on a project (using Dreamweaver) but the code isn't being run.

当我检查源代码时,PHP 代码显示为 HTML 标记(我可以在源代码中看到它).Apache 运行正常(我正在使用 XAMPP),PHP 页面正在正常打开,但 PHP 代码没有被执行.

When I check the source code, the PHP code appears as HTML tags (I can see it in the source code). Apache is running properly (I'm working with XAMPP), the PHP pages are being opened properly but the PHP code isn't being executed.

有人对正在发生的事情有什么建议吗?

Does someone have a suggestion about what is happening?

注意:文件已经命名为filename.php

代码..:

<?
include_once("/code/configs.php");
?>

推荐答案

听起来您的配置有问题,您可以检查以下几点:

Sounds like there is something wrong with your configuration, here are a few things you can check:

  1. 确保 PHP 已正确安装并运行.这可能听起来很傻,但你永远不会知道.一个简单的检查方法是从命令行运行 php -v 并查看是否返回版本信息或任何错误.

  1. Make sure that 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 a command line and see if returns version information or any errors.

确保 PHP 模块在 Apache 的 httpd.conf 中列出且未注释 这应该类似于 LoadModule php5_module "c:/php/php5apache2_2.dll" 在文件中.搜索LoadModule php,确保前面没有注释(;).

Make sure that the PHP module is listed and uncommented inside of your Apache's httpd.conf This should be something like LoadModule php5_module "c:/php/php5apache2_2.dll" in the file. Search for LoadModule php, and make sure that there is no comment (;) in front of it.

确保 Apache 的 httpd.conf 文件中包含 PHP MIME 类型.这应该类似于 AddType application/x-httpd-php .php.这告诉 Apache 将 .php 文件作为 PHP 运行.搜索 AddType,然后确保有一个 PHP 条目,并且没有注释.

Make sure that Apache's httpd.conf file has the PHP MIME type in it. This should be something like AddType application/x-httpd-php .php. This tells Apache to run .php files as PHP. Search for AddType, and then make sure there is an entry for PHP, and that it is uncommented.

确保您的文件具有 .php 扩展名,或者在第 3 点 MIME 定义中指定的任何扩展名,否则它将不会作为 PHP 执行.

Make sure your file has the .php extension on it, or whichever extension specified in the MIME definition in point #3, otherwise it will not be executed as PHP.

确保您没有使用 短标签 在 PHP 文件 (<?) 中,这些默认情况下并非在所有服务器上启用,因此不鼓励使用它们.使用 <?php 代替(或 使用 short_open_tag=On 在 php.ini 中启用短标签,如果您有依赖它们的代码).

Make sure you are not using short tags in the PHP file (<?), these are not enabled on all servers by default and their use is discouraged. Use <?php instead (or enable short tags in your php.ini with short_open_tag=On if you have code that relies on them).

确保您通过网络服务器访问您的文件,使用像 http://localhost/file.php 这样的 URL,而不是通过本地文件访问 file://localhost/www/file.php

Make sure you are accessing your file over your webserver using an URL like http://localhost/file.php not via local file access file://localhost/www/file.php

最后查看 PHP 手册了解更多设置提示.

这篇关于PHP代码没有被执行,但代码显示在浏览器源代码中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 19:04