如何打开 file.html 并使用提交按钮使用 fwrite?
how to open file.html and use fwrite using submit button?
基本上我想生成一个感谢页面,每次用户在写完他们的电子邮件(我将通过 fwrite 获取)后点击提交按钮时,都会生成一个新的 html 页面并写下感谢在上面。我已经完成了列表部分:
<?php
if(isset($_POST['submit']))
{
$email =$_POST['email'];
$file = fopen("list.txt","a+") or die("file not open");
$s= $email;
fputs($file,$s." ") or die("data not written");
fclose($file);
}
?>
完成脚本逻辑后,回显一些 HTML 以在浏览器中显示网页。所以,在 fclose($file); }
之后添加:
echo "<html><head><title>Thanks!</title></head>
<body>
<p>Thank you.</p>
</body>
</html>" ;
为什么你只是为了谢谢而生成新页面。我会建议您创建一个新页面 ("/thanks.php"),您可以在其中像这样动态地传递电子邮件。
<?php
if(isset($_POST['submit']))
{
$email =$_POST['email'];
echo "<html><head><title>Thanks!</title></head>
<body>
<p>$email</p>
</body>
</html>" ;
}
创建一个新页面,将其命名为 thank_you.php
并在 fclose($file);
之后立即重定向至感谢页面。
<?php
if(isset($_POST['submit']))
{
$email =$_POST['email'];
$file = fopen("list.txt","a+") or die("file not open");
$s= $email;
fputs($file,$s." ") or die("data not written");
fclose($file);
header("Location: thank_you.php");
}
?>
基本上我想生成一个感谢页面,每次用户在写完他们的电子邮件(我将通过 fwrite 获取)后点击提交按钮时,都会生成一个新的 html 页面并写下感谢在上面。我已经完成了列表部分:
<?php
if(isset($_POST['submit']))
{
$email =$_POST['email'];
$file = fopen("list.txt","a+") or die("file not open");
$s= $email;
fputs($file,$s." ") or die("data not written");
fclose($file);
}
?>
完成脚本逻辑后,回显一些 HTML 以在浏览器中显示网页。所以,在 fclose($file); }
之后添加:
echo "<html><head><title>Thanks!</title></head>
<body>
<p>Thank you.</p>
</body>
</html>" ;
为什么你只是为了谢谢而生成新页面。我会建议您创建一个新页面 ("/thanks.php"),您可以在其中像这样动态地传递电子邮件。
<?php
if(isset($_POST['submit']))
{
$email =$_POST['email'];
echo "<html><head><title>Thanks!</title></head>
<body>
<p>$email</p>
</body>
</html>" ;
}
创建一个新页面,将其命名为 thank_you.php
并在 fclose($file);
之后立即重定向至感谢页面。
<?php
if(isset($_POST['submit']))
{
$email =$_POST['email'];
$file = fopen("list.txt","a+") or die("file not open");
$s= $email;
fputs($file,$s." ") or die("data not written");
fclose($file);
header("Location: thank_you.php");
}
?>