WebServ/www/public/M3/06/userManipulation.php

47 lines
1.0 KiB
PHP
Raw Permalink Normal View History

2024-09-06 13:22:36 +00:00
<!DOCTYPE html>
<html lang="se">
<head>
<meta charset="UTF-8">
<title>Person write</title>
</head>
<body>
<?php
include("User.php");
function addUser($user)
{
2024-09-13 12:56:16 +00:00
$file = "../../../userData/M3-06-users.dat";
2024-09-06 13:22:36 +00:00
if(file_exists($file)) {
$users = unserialize(file_get_contents($file));
$users[] = $user;
file_put_contents($file, serialize($users));
}
else {
$users = array();
$users[] = $user;
file_put_contents($file, serialize($users));
}
}
function isPresent($userToFind)
{
2024-09-13 12:56:16 +00:00
$file = "../../../userData/M3-06-users.dat";
2024-09-06 13:22:36 +00:00
if (file_exists($file)) {
$userArray = unserialize(file_get_contents($file));
}
else return false;
foreach($userArray as $user) {
if($userToFind->getUsername() == $user->getUsername() && $userToFind->getPassword() == $user->getPassword()) return true;
}
return false;
}
?>
</body>
</html>