gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-27 23:02:59 27 4
gpt4 key购买 nike

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

html 文件中完成此操作的位置已经分配了一个单独的函数,并且除了没有创建文本文件之外一切正常。'我尝试使用“file_put_contents ($file, $var1, Var2 )”将其添加到单独的 php 部分中ETC。'与 ' file_append标志'设置。虽然运行时没有出现错误,但也没有文件。是的,我在该文件夹中拥有完整的读/写权限

有人告诉我 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/ 上了解更多信息

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

关于javascript - 将变量的内容附加到 html 内的文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36883390/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com