[英]Appending the contents of variable to a text file within html
我正在嘗試創建一個用戶列表,包括他們的所有數據,因為每個用戶都被添加到網站中。 這包括登錄名、密碼、名字姓氏及其條目的創建時間。
完成此操作的 html 文件內的位置已經分配了一個單獨的功能,除了沒有創建文本文件外,一切正常。 ' 我嘗試使用' file_put_contents ($file, $var1, Var2 )
等在單獨的 php 部分中添加它。 設置了“ 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”文件夾中。
你會想要:
嘗試這個:
<?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/上了解更多信息
如果您仍然遇到問題,請發布您的代碼以及有關文件保存位置的更多信息,我很樂意查看。 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.