【发布时间】: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 只是<h1> 和<p> 的一些基本格式。
另外还有一个person.txt与index.php在同一目录下的文件。
所以在 localhost 上,Chrome 浏览器不会打印“Success”、更新我的person.txt 或打印“finished”。但是,当我使用 ftp 将 index.php、person.txt 和 style.css 上传到我的 Web 服务器时,所有 php 代码都可以正常工作。谁可以帮我这个事?
附:该网站是here。
【问题讨论】:
-
你安装PHP了吗?
-
您的本地主机上是否运行了正确的 Web 服务器?
-
请提及您正在使用的软件包,例如wamp 服务器...
-
要么您没有安装服务器,要么没有正确配置服务器
-
没有 Chrome 是客户端,要使用 PHP,您需要在本地设置 Web 服务器并运行 PHP 服务器