我在 php 邮件表单上有这段代码,直到最近才使用。
//Open last-order.txt file for getting the order number $readFile = fopen("./order.txt", "r") or die("Unable to open file!"); $orden= fread($readFile,filesize("./order.txt")); fclose($readFile); ++$orden; $writeFile= fopen("./order.txt", "w") or die("Unable to open file!"); fwrite($writeFile, $orden); fclose($writeFile); if (!preg_match("~^(?:f|ht)tps?://~i", $website)) $website = "http://" . $website; $website = filter_var($website, FILTER_VALIDATE_URL); $email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL); $participantes = filter_var($_POST["participantes"], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
它引用一个名为 order.txt 的 TXT 文件,该文件读取该文件并在每次读取时将数字加一。不幸的是,当托管提供商让我对服务感到冷落时,我丢失了这个文件,无法访问服务器或其备份。
这是我放在 TXT 文件中的文本:
Orden: 8000
我并不是一个真正熟练的 PHP 编码员,因此我尝试重新创建它或使其工作,但没有结果。
这是错误:
[03-Jan-2023 13:29:22 America/Mexico_City] PHP Warning: Undefined variable $email_content in /home/guillerm/iefa.com.mx/rsvp/php/reserve.php on line 78 [03-Jan-2023 13:29:22 America/Mexico_City] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/guillerm/iefa.com.mx/rsvp/php/reserve.php:78) in /home/guillerm/iefa.com.mx/rsvp/php/reserve.php on line 149
任何为我指明正确方向的帮助,我将不胜感激。感谢您查看此内容。
P粉8250797982024-04-03 00:59:44
it's literally just supposed to be a number. replace Orden: 8000
with just 8000
.
顺便说一句,该代码是线程不安全,如果您运行,数字可能会发生冲突/重复同时执行多个代码实例;如果需要线程安全,您可以这样做
$readFile = fopen("./order.txt", "c+b") or die("Unable to open file!"); flock($readFile, LOCK_EX); $orden = (int)stream_get_contents($readFile); ++$orden; rewind($readFile); fwrite($readFile, (string) $orden); flock($readFile, LOCK_UN); fclose($readFile);