【问题标题】:PHP showing up as plain textPHP 显示为纯文本
【发布时间】:2014-03-07 20:54:48
【问题描述】:

我有一个简单的表单和 php 文件。当我单击提交时,它只会拉出一个包含 resources.php 内容的纯文本文件。为什么会发生这种情况?

index.html

<html>
<head>
</head>
<body>

    <form action="resources.php" method='POST'>

        <input type="text"  placeholder="Name" name="name"><br>
        <input type="text"  placeholder="Organization" name="organization"><br>
        <input type="email" placeholder="E-Mail" name="email"><br>
        <input type="text"  placeholder="Street Address" name="streetaddress"><br>
        <input type="text"  placeholder="Phone Number" name="phonenumber"><br>
        <input type="text"  placeholder="What is three plus four?" name="human"><br>

        <input type="submit">

</form>
</body>
</html>

还有resources.php文件...

<html>
<head></head>
<body>

<?php

    echo '<pre>'.$_POST.'<pre>';

?>

</body>
</html>

谢谢。

【问题讨论】:

  • 如果您在 客户端上看到 PHP 代码,这意味着您的 Web 服务器没有处理该代码。您可能需要在服务器上重新安装和/或重新配置 PHP。
  • 您的服务器未配置为执行 PHP,或者您已将文件保存为 .html,这些文件也不作为 PHP 执行。另外,echo $_POST 将不起作用。你只会得到字面意思Array 作为输出。
  • 您的网络服务器是否识别并执行 PHP 文件?例如,如果您使用的是 Apache,则需要在 conf 中的某处添加类似 AddType x-httpd-php .php 的行,并且 libphp.so 文件需要作为模块提供。
  • @MarcB print_r($_POST)

标签: php html forms


【解决方案1】:

以下是您问题的可能答案:

  1. WEB 服务器未正确处理您的 PHP 代码,因为 php 未安装或配置错误。
  2. 您根本没有使用 Web 服务器。确保从本地主机(或任何您的服务器)加载您的页面,而不是从文件本身 例如:localhost/path/to/index.html 而不是 c://program 文件...

【讨论】:

  • resources.php 需要可执行吗?
猜你喜欢
  • 2012-01-31
  • 2016-02-08
  • 2016-07-25
  • 2015-09-03
  • 1970-01-01
  • 1970-01-01
  • 2014-09-18
  • 2013-05-19
  • 2016-05-25
相关资源
最近更新 更多