PHP:
<?php require "php/RegistrationPost.php" ?>
<?php
class RegistrationDB{
private $userList;
private $idCounter;
public function __construct(){
$this->userList = array();
$this->idCounter = 0;
}
public function createUser($username, $email, $password, $confrimePassword, $image){
try{
$this->verifyUsername($username, $email, $password, $confrimePassword, $image);
global $idCounter;
$createdUser = new RegistrationPost($username, $email, $password, $confrimePassword, $image);
$this->userList[$idCounter] = $createdUser;
$this->idCounter++;
for($i = 0; $i < count($this->userList[$i]); $i++){
echo "Name: " . $this->userList[$i]->getUsername();
}
echo " Registration successfuly ";
}catch(Exception $e){
echo $e->getMessage();
}
}
private function verifyUsername($username, $email, $password, $confrimePassword, $image) {
if (!isset($username) || !is_string($username) || trim($username == "")) {
throw new Exception("Error: Username invalid");
}
if (!isset($email) || !is_string($email) || trim($email == "") ||
!preg_match(
'/^[_a-zA-Z0-9_\-.]+@[a-zA-Z0-9\-.]+\.[a-zA-Z]{2,6}$/',
$email)) {
throw new Exception("Error: E-Mail invalid");
}
if (!isset($password) || !is_string($password) || trim($password == "")) {
throw new Exception("Error: Password invalid");
}
if (!isset($confrimePassword) || !is_string($confrimePassword) || trim($confrimePassword == "")) {
throw new Exception("Error: Confrimepassword invalid");
}
if($password !== $confrimePassword){
throw new Exception("Error: Passwörter stimmen miteinander nicht überein!");
}
}
public function onLoginsuccessful($username, $password){
$loginSuccessful = false;
for($i = 0; $i < count($this->userList); $i++){
$createdUser = $this->userList[$i];
if($username == $createdUser->getUsername() && $password == $createdUser->getPassword()){
$loginSuccessful = true;
break;
}
}
return $loginSuccessful;
}
}
?>
for($i = 0; $i < count($this->userList[$i]); $i++){
echo "Name: " . $this->userList[$i]->getUsername();
} hab immer diese Fehlermeldungen:
Warning: Undefined array key 0
Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, null given in
wie kann ich sonst in der Array die registrierten Nutzen speichern, so dass bei der Anmeldung vergleichen kann.