【问题标题】:php not working on localhost but on web server?php不在本地主机上工作,但在Web服务器上工作?
【发布时间】:2014-01-15 17:03:19
【问题描述】:

我是 php 的初学者,我遇到了一个奇怪的问题,即 php 代码无法在 localhost 上运行(使用 D 盘上的 Chrome 打开 index.php)但在 Web 服务器上运行。这是我的 index.php。我搜索了解决方案,但没有找到。

<!DOCTYPE html>  
<html lang="en">  
<head>
<meta charset="utf-8" />  
<link rel="stylesheet" type="text/css" href="style.css">
<title>Hello World!</title>  
</head>  
<body>
<h1>Hello World!</h1>
<p><?php echo "Success"; ?></p>
<p>Welcome! This is my personal webpage. </p>
<p style="color:red">This is a red font. </p>
<a href="subpage1.html"><p>Link</p></a>
<p><?php 
    $file = 'people.txt';
    // Open the file to get existing content
    $current = file_get_contents($file);
    // Append a new person to the file
    $current .= "John Smith\n";
    // Write the contents back to the file
    print file_put_contents($file, $current);
    echo "finished";
     ?></p>
</body>
</html>

style.css 只是&lt;h1&gt;&lt;p&gt; 的一些基本格式。

另外还有一个person.txtindex.php在同一目录下的文件。

所以在 localhost 上,Chrome 浏览器不会打印“Success”、更新我的person.txt 或打印“finished”。但是,当我使用 ftp 将 index.phpperson.txtstyle.css 上传到我的 Web 服务器时,所有 php 代码都可以正常工作。谁可以帮我这个事?

附:该网站是here

【问题讨论】:

  • 你安装PHP了吗?
  • 您的本地主机上是否运行了正确的 Web 服务器?
  • 请提及您正在使用的软件包,例如wamp 服务器...
  • 要么您没有安装服务器,要么没有正确配置服务器
  • 没有 Chrome 是客户端,要使用 PHP,您需要在本地设置 Web 服务器并运行 PHP 服务器

标签: php html


【解决方案1】:

这是一个选项,因为 Chrome 只是一个没有 PHP 服务器的网络浏览器。我将它用于我的本地 PHP 和网络服务器

http://www.apachefriends.org/en/xampp.html

【讨论】:

    【解决方案2】:

    您的本地主机上是否安装了 PHP 或 Web 服务器?如果这样做,则可能取决于本地主机上的设置。

    【讨论】:

      【解决方案3】:

      我希望你已经安装了 wamp 或 xampp。如果你在窗户上。 将您的代码放在根目录或 htdocs 文件夹中。 使用

      访问您的代码
                         http://localhost/yoursite/index.php
      

      如果您遇到任何错误,请在此处发布,以便您轻松猜测代码中的问题

      【讨论】:

        猜你喜欢
        • 2016-08-04
        • 2013-04-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多