【发布时间】:2021-10-11 01:56:18
【问题描述】:
我尝试在我的 Mac 上托管一个简单的网站。我的目标是制作一个每个人都可以输入文本的表单,然后这段文本将显示在 HTML 主页中。我遇到了两个问题:
-
当我运行
php submit.php时,我可以在mylog.log中看到更新,但在使用浏览器 (Safari) 并访问网站本身时却看不到。 -
即使我设法写入文件,我也不知道如何让 HTML 与之交互以显示内容。
这是index.html中的代码:
<form action="submit.php" method="post" target="_self">
<input type="text" id="textform2" name="msg">
<input type="submit">
</form>
还有submit.php:
<!DOCTYPE html>
<html>
<head>
<title>Processing</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<?php
$message = 'hi';
$file = 'mylog.log';
$handle = fopen($file, 'w');
fwrite($handle, $message);
fclose($handle);
?>
<p class="par">Our server is processing your request. You will be redirected…</p>
<script> location.replace("http://johann.local"); </script>
</body>
</html>
-
我把这些文件放在
Macintosh/Library/WebServer/Documents。 -
不需要消毒,因为它只会托管在我的私人 WiFi 网络上。
【问题讨论】:
-
您使用哪个网络服务器?您可以尝试在 Documents 目录下运行
php -S localhost:5000,然后尝试转到localhost:5000 -
效果很好!太感谢了。 (我的第二个问题仍然需要帮助)
-
没问题 :) 。而且,我不明白你的第二个问题。你能再解释一下吗?谢谢
-
假设我在
mylog.log中有文本“我爱PHP”。如何将 HTML 元素的内容设置为“我爱 PHP”?