Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

How to make .php write only one line in data.txt or make a new file evert time?

I want to make that .php to make write only one line in "data.txt" or make a new text file every time.
How should i do it?

<?php
header('Location: https://www.xxx.com');
$txt = "data.txt";
$fh = fopen($txt, 'w+');
if (isset($_POST['field1']) && isset($_POST['field2'])) { // check if both fields are set
$txt=$_POST['field1'].' - '.$_POST['field2'];
file_put_contents('data.txt',$txt."\n",FILE_APPEND); //log to data.txt
exit();
}
fwrite($fh,$txt); // write information to the file
fclose($fh); // close the file

?>?
Not really sure what exactly are you asking.
The PHP part MUST be above all of your HTML, and form should be in the body of the HTML.
Why are you sending login information via text file?
$fileHandle = fopen(‘filename’, ‘a’);
fwrite($fileHandle, ‘new line\r\n’);
fclose($fileHandle);
[Image: Syr3DlV.png]
If I understood right, you want the file to only one line every time (The most recent one)? If so, your code is fine, just take off the FILE_APPEND flag from your function, and if the file exists, it always creates a new one and overwrites the current one.

So this line:
PHP Code

<?php 
file_put_contents
('data.txt',$txt."\n",FILE_APPEND); //log to data.txt 

Should look like this:
PHP Code

<?php 
file_put_contents
('data.txt',$txt); //log to data.txt 

That's it!

You can read about the function here: https://secure.php.net/manual/en/functio...ntents.php, it has a section describing what each flags does, and what the function normal behavior should look like :)


Possibly Related Threads...
Thread / Author Replies Views Last Post
[PHP] by Professional HackerJan 26, 2022 08:01 PM 2 140 Jan 26, 2022 08:01 PM
Last Post: Professional Hacker
[PHP] by BulgarianFeb 21, 2020 12:33 AM 5 372 Feb 21, 2020 12:33 AM
Last Post: Backbone
[PHP] by APΣXMay 22, 2019 04:14 PM 2 210 May 22, 2019 04:14 PM
Last Post: APΣX