<?phpclass Membre{	const DEFAULT_BANNER = "pictures/bande.png";	protected $id;	protected $password;	protected $pseudo;	protected $adminLevel;	protected $dateCreation;	protected $requiredBanner;	protected $personnalMessage;	protected $connected;	public function  __construct($id = NULL,$pass = NULL){		$this->id = $id ?? $_SESSION['session_id'];		$this->password = $pass ?? $_SESSION['session_mdp'];		$connected = FALSE;	}	public function connect(){		$req = $GLOBALS ['bdd']->prepare ( 'SELECT * FROM users WHERE ID=?' );		$req->execute (array($this->id));		if ($rep = $req->fetch ()){			$connected = password_verify ( $this->pass, $rep ['mdp'] );			$this->adminLevel = $connected?$result ['administration']:-1;			$this->pseudo = $connected?$result['pseudo']:NULL;			if($connected)decodeData($rep['data']);			return $this->connected = $connected;		}else{			$req->closeCursor ();			return $this->connected = FALSE;		}	}	public function hasPersonnalMessage(){		return isset($this->personnalMessage);	}	public function showPersonnalMessage(){		$msg = $this->personnalMessage;		$this->personnalMessage = NULL;		return $msg;	}	private function decodeData($data) {		$jsonData = json_decode($data);		//Set the data's required_banner if it is defined , otherwise sets the DEFAULT_BANNER		$this->requiredBanner = $jsonData['requiredBanner'] ?? self::DEFAULT_BANNER;		$this->personnalMessage = $jsonData['personnalMessage'] ?? NULL;	}	private function encodeData(){		$jsonArray = array();		//Set requiredBanner only if it is different from DEFAULT_BANNER		$jsonArray['requiredBanner'] = $this->requiredBanner !== self::DEFAULT_BANNER ? $this->requiredBanner : NULL;		$jsonArray['personnalMessage'] = $this->personnalMessage ?? NULL;		return json_encode($jsonArray);	}		public function getAdminLevel(){		return $this->adminLevel;	}	public function getBanner() {		return $this->requiredBanner;	}	public function isConnected(){		return $connected;	}	public static function tryToConnect($pseudo = NULL,$mdp = NULL){		$pseudo = $pseudo ?? $_POST ['pseudo'];		$mdp = $mdp ?? $_POST ['mdp'];		$req = $GLOBALS ['bdd']->prepare ( 'SELECT * FROM users WHERE pseudo=?' );		$req->execute ( array (	$pseudo	) );		$reponce = $req->fetch ();		if ($reponce != NULL) {			if (password_verify ( $mdp, $reponce ['mdp'] )) {				$req->closeCursor ();				return $reponce ['ID'];			} else {				$req->closeCursor ();				return 'errormdp';			}		} else {			$req->closeCursor ();			return 'errorpseudo';		}	}	public static function registerPerson($pseudo, $mdp) {		$req = $GLOBALS ['bdd']->prepare ( "SELECT * FROM users WHERE pseudo=?" );		$req->execute (array($_POST ['pseudo']));		if ($req->fetch ()) return 'usedPseudo';		$req = $GLOBALS ['bdd']->prepare ( 'INSERT INTO users(pseudo,mdp,date_creation) VALUES (?,?,NOW())' );		$req->execute(array($_POST ['pseudo'],password_hash ( $_POST ['mdp'], PASSWORD_DEFAULT)));		return 'ok';	}}