TXT file missing from PHP form. Any idea what it should contain?
P粉717595985
P粉717595985 2024-04-02 10:35:40
0
1
539

I have this code on a php mail form that I didn't use until recently.

//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);

It references a TXT file called order.txt, which reads the file and increments the number by one each time it is read. Unfortunately, when the hosting provider gave me the cold shoulder, I lost this file and was unable to access the server or its backups.

This is the text I put in the TXT file:

Orden: 8000

I'm not really a proficient PHP coder, so I tried to recreate it or make it work, but to no avail.

This is an error:

[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

Any help pointing me in the right direction would be greatly appreciated. Thank you for viewing this content.

P粉717595985
P粉717595985

reply all(1)
P粉825079798

it's literally just supposed to be a number. replace Orden: 8000 with just 8000.

BTW, this code is thread-unsafe , the numbers may conflict/duplicate if you run multiple instances of the code concurrently; if you need to be thread-safe, you can do this

$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);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template