将变量的内容附加到 html 中的文本文件中

Appending the contents of variable to a text file within html

本文关键字:html 文件 文本 变量      更新时间:2023-09-26

我正在尝试创建一个用户列表,包括他们的所有数据,因为每个用户都被添加到网站。 这包括登录名、密码、名字姓氏及其条目的创建时间。

html文件中完成此操作的位置已经分配了一个单独的功能,除了没有创建文本文件外,一切都可以正常工作。'我尝试使用带有"file_append标志"设置的"file_put_contents ($file, $var1, Var2 )等"的单独 php 部分添加它。 虽然我在运行时没有收到任何错误,但我也没有收到文件。 是的,我在该文件夹中具有完全读/写权限

我被告知jQuery可能会起作用,但我不知道如何做到这一点。
所有信息都收集到 5 个变量中。 我需要最简单的方法来附加在文本文件的单行条目中创建的这些内容(Userlist.txt)该文本文件可以在添加所有用户时存储信息。

document.getElementById('username').value = username; document.getElementById('password').value = password; document.getElementById('confirm').value = password;

这是我尝试使用的
PHP
<?php $file = 'people.txt'; ($file, $timeValue $first_name $username $password, FILE_APPEND | LOCK_EX); ?>

    '$file = 'cache/newfile.txt';
      if(usernameLength == 0){
        var first_name = document.getElementById('first_name').value;
        var last_name = document.getElementById('last_name').value;
        var composed = first_name+last_name;
        var fullHash = CryptoJS.MD5(composed).toString();       
        var username = fullHash.substr(0,8);
        var password = fullHash.substr(fullHash.length - 8);
        document.getElementById('username').value = username;
        document.getElementById('password').value = password;
        document.getElementById('confirm').value = password     
        $date = date('d/m/Y H:i:s'); 
        $output =  $date . "'t" . $first_name . "'t" . $last_name . "'t" . $password;
        file_put_contents($file, $output, FILE_APPEND | LOCK_EX);>

尝试了 html 中建议的编辑,我承认我不确定我在做什么。 发生的情况是整个函数在激活时失败。 没有错误,但不会创建文件并且输入停止。谢谢

例如,假设您的脚本存储在"public_html"文件夹中,并且您希望将输出保存到"public_html/secure"文件夹中。

您需要:

  1. 将所有变量保存到一个字符串中
  2. 将此字符串保存到输出文件中

试试这个:

<?php
  //Define where the output will be saved
  $file = 'secure/file.txt';
  //Define your Timezone if not already explicitly defined in your php.ini
  date_default_timezone_set('Europe/London');
  //Store your variables in a string, separated by a tab ('t)
  $date = date('d/m/Y H:i:s'); //Gets the date in format 31/01/2016 12:59:59
  $output =  $date . "'t" . $var1 . "'t" . $var2 . "'t" . $var3;
  file_put_contents($file, $output, FILE_APPEND | LOCK_EX);
?>

要探索更多功能,请搜索要自定义的功能或了解更多信息 http://www.php.net/

如果您仍然遇到问题,请发布您的代码并提供有关文件保存位置的更多信息,我很乐意查看。: )