Tôi đang cố gắng viết tên người dùng và mật khẩu vào một dòng mới trong tệp TXT. Đầu ra phải là một cái gì đó như thế này trong tệp TXT. Tôi biết điều này không an toàn lắm nhưng nó chỉ nhằm mục đích học tập
Sebastian password
John hfsjaijn
Đây là những gì tôi có cho đến nay
if[isset[$_GET['register']]] //
{
$user = $_GET['username'];
$password=$_GET['password'];
$fh = fopen["file.txt","a+"];
fwrite[$fh,$user."\n"]; //write to txtfile
fwrite[$fh,$password."\n"]; // write to txtfile
fclose[$fh];
}
Chỉnh sửa: Đây là giải pháp cho tôi:
if [isset[$_POST['register']]] {
$user = $_POST['username'];
$password = $_POST['password'].PHP_EOL;
$fh = fopen["file.txt","a+"];
fwrite[$fh,$user." ".$password]; //write to txtfile
fclose[$fh];
}
Martijn
15,5K4 Huy hiệu vàng36 Huy hiệu bạc66 Huy hiệu Đồng4 gold badges36 silver badges66 bronze badges
hỏi ngày 28 tháng 2 năm 2013 lúc 7:56Feb 28, 2013 at 7:56
6
Sử dụng
if[isset[$_GET['register']]] //
{
$user = $_GET['username'];
$password=$_GET['password'];
$fh = fopen["file.txt","a+"];
fwrite[$fh,$user."\n"]; //write to txtfile
fwrite[$fh,$password."\n"]; // write to txtfile
fclose[$fh];
}
6 sản xuất if[isset[$_GET['register']]] //
{
$user = $_GET['username'];
$password=$_GET['password'];
$fh = fopen["file.txt","a+"];
fwrite[$fh,$user."\n"]; //write to txtfile
fwrite[$fh,$password."\n"]; // write to txtfile
fclose[$fh];
}
7 hoặc if[isset[$_GET['register']]] //
{
$user = $_GET['username'];
$password=$_GET['password'];
$fh = fopen["file.txt","a+"];
fwrite[$fh,$user."\n"]; //write to txtfile
fwrite[$fh,$password."\n"]; // write to txtfile
fclose[$fh];
}
8$data = 'my data' . PHP_EOL . 'my data';
$fp = fopen['my_file', 'a'];
fwrite[$fp, $data];
fclose[$fp];
// đầu ra tệp
my data
my data
Nến
1.1692 Huy hiệu vàng21 Huy hiệu bạc 50 Huy hiệu Đồng2 gold badges21 silver badges50 bronze badges
Đã trả lời ngày 28 tháng 2 năm 2013 lúc 8:03Feb 28, 2013 at 8:03
Dino Babudino BabuDino Babu
5.7663 Huy hiệu vàng23 Huy hiệu bạc33 Huy hiệu Đồng3 gold badges23 silver badges33 bronze badges
1
Bạn nối một dòng mới cho cả tên người dùng và mật khẩu, tức là đầu ra sẽ giống như
Sebastian
password
John
hfsjaijn
sử dụng
if[isset[$_GET['register']]] //
{
$user = $_GET['username'];
$password=$_GET['password'];
$fh = fopen["file.txt","a+"];
fwrite[$fh,$user."\n"]; //write to txtfile
fwrite[$fh,$password."\n"]; // write to txtfile
fclose[$fh];
}
9 thay vào đó để có cả hai trên một dòng. Hoặc sử dụng fputcsv [] để ghi dữ liệu và if [isset[$_POST['register']]] {
$user = $_POST['username'];
$password = $_POST['password'].PHP_EOL;
$fh = fopen["file.txt","a+"];
fwrite[$fh,$user." ".$password]; //write to txtfile
fclose[$fh];
}
0 để tìm nạp nó. Bằng cách này, ít nhất bạn sẽ tránh các vấn đề mã hóa như ví dụ: với if [isset[$_POST['register']]] {
$user = $_POST['username'];
$password = $_POST['password'].PHP_EOL;
$fh = fopen["file.txt","a+"];
fwrite[$fh,$user." ".$password]; //write to txtfile
fclose[$fh];
}
1Or use fputcsv[] to write the data and
if [isset[$_POST['register']]] {
$user = $_POST['username'];
$password = $_POST['password'].PHP_EOL;
$fh = fopen["file.txt","a+"];
fwrite[$fh,$user." ".$password]; //write to txtfile
fclose[$fh];
}
0 to fetch it. This way you would at least avoid encoding problems like e.g. with if [isset[$_POST['register']]] {
$user = $_POST['username'];
$password = $_POST['password'].PHP_EOL;
$fh = fopen["file.txt","a+"];
fwrite[$fh,$user." ".$password]; //write to txtfile
fclose[$fh];
}
1...I E. Đặt tất cả những điều sai lầm khi lưu trữ mật khẩu đơn giản trong các tệp đơn giản và sử dụng _get cho loại hoạt động này [sử dụng _Post thay thế] ;-]
Đã trả lời ngày 28 tháng 2 năm 2013 lúc 8:01Feb 28, 2013 at 8:01
VolkerkvolkerkVolkerK
94.3K20 Huy hiệu vàng162 Huy hiệu bạc225 Huy hiệu Đồng20 gold badges162 silver badges225 bronze badges
2
fwrite[$handle, "
"."\r\n"];
Thêm điều này dưới
$password = $_POST['password'].PHP_EOL;
đây. .
Đã trả lời ngày 2 tháng 12 năm 2014 lúc 20:53Dec 2, 2014 at 20:53
Làm thế nào về bạn lưu trữ nó như thế này? Có thể ở tên người dùng: Định dạng mật khẩu, vì vậy
sebastion:password123
anotheruser:password321
Sau đó, bạn có thể sử dụng
if [isset[$_POST['register']]] {
$user = $_POST['username'];
$password = $_POST['password'].PHP_EOL;
$fh = fopen["file.txt","a+"];
fwrite[$fh,$user." ".$password]; //write to txtfile
fclose[$fh];
}
2 để phân tích dữ liệu về kết thúc của bạn.Đã trả lời ngày 26 tháng 1 năm 2019 lúc 17:05Jan 26, 2019 at 17:05
Bài viết đề xuất
- Đăng lại
Xin chào
Tôi có mã này: