Я получаю эту ошибку при попытке создать страницу входа в систему:
Warning: file_put_contents(/users/userlist.txt): failed to open stream: Permission denied in /Library/WebServer/Documents/register_draft.php on line 17
Warning: file_put_contents(/users/passlist.txt): failed to open stream: Permission denied in /Library/WebServer/Documents/register_draft.php on line 18
Warning: file_put_contents(/users/pinlist.txt): failed to open stream: Permission denied in /Library/WebServer/Documents/register_draft.php on line 19
Warning: Cannot modify header information - headers already sent by (output started at /Library/WebServer/Documents/register_draft.php:17) in /Library/WebServer/Documents/register_draft.php on line 20
Я создал папку, в которую нужно поместить всех пользователей с именем "users", в моем /Library /Webserver /Documents /
Вот мой код:
<?php
$file1 = '/users/userlist.txt';
$file2 = '/users/passlist.txt';
$file3 = '/users/pinlist.txt';
$user = usermail;
$pass = password;
$pin = pi;
$safeUser = testUserInput($user);
$safePass = testUserInput($pass);
$safePin = testUserInput($pin);
if ($safeUser != "unsafe" && $safeUser != "empty" && $safeUser != "spaces") {
if ($safePass != "empty" && $safePass != "unsafe" && $safePass != "spaces") {
if ($safePin != "empty" && $safePin != "unsafe" && $safePin != "spaces") {
$hashedPass = password_hash($safePass, PASSWORD_BCRYPT);
file_put_contents($file1, $safeUser . "<br>", FILE_APPEND | LOCK_EX);
file_put_contents($file2, $hashedPass . "<br>", FILE_APPEND | LOCK_EX);
file_put_contents($file3, $safePin . "<br>", FILE_APPEND | LOCK_EX);
header("Location: ../users"); //change this to direct user to login page, account successfully created
}
}
} else {
header("Location: ../users"); //change this to direct user back to registration page with error prompt
}
function testUserInput($x) {
$test = strpbrk($x,"<>/\;()%-+.=,");
if ($test != false) {
$x = "unsafe";
} elseif (strlen($x) == 0) {
$x = "empty";
} elseif (ctype_space($x)) {
$x = "spaces";
}
return $x;
}
?>
Если вы видите какие-либо другие проблемы с кодом, пожалуйста, дайте мне знать. Благодарю.