41 lines
1.0 KiB
PHP
41 lines
1.0 KiB
PHP
|
<?php
|
||
|
|
||
|
$file = "../../../userM3.dat";
|
||
|
|
||
|
function addUser($newUser, $file) {
|
||
|
|
||
|
if(file_exists($file)){
|
||
|
$users = unserialize(file_get_contents($file));
|
||
|
}else{
|
||
|
echo "Filen finns inte!!!";
|
||
|
exit;
|
||
|
}
|
||
|
if (!is_array($users)) {
|
||
|
$users = [];
|
||
|
} else {
|
||
|
// If file does not exist, initialize as an empty array
|
||
|
$users = [];
|
||
|
}
|
||
|
$users[] = $newUser;
|
||
|
file_put_contents($file, serialize($users));
|
||
|
}
|
||
|
|
||
|
function readUser($file, $användarnamn, $lösenord) {
|
||
|
if(file_exists($file)){
|
||
|
$users = unserialize(file_get_contents($file));
|
||
|
}else{
|
||
|
// Filen finns ej!! Kör om programmet “personWrite.php”
|
||
|
}
|
||
|
|
||
|
header('Content-Type: text/html; charset=utf-8');
|
||
|
|
||
|
foreach($users as $user) {
|
||
|
if ($user->getAnvändarnamn() == $användarnamn && $user->getLösenord() == $lösenord) {
|
||
|
echo('Välkommen ' . $user->getFörnamn() . " " . $user->getEfternamn());
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
?>
|
||
|
</body>
|
||
|
</html>
|