public static function registerUser($data)
 {
     $errmsg = '';
     $user = new self();
     if ($data['data']['mail'] == '') {
         $user->errmsg = Texter::get('user|registrationNoMailFail');
     }
     if (!filter_var($data['data']['mail'], FILTER_VALIDATE_EMAIL)) {
         $user->errmsg = Texter::get('user|registrationNoValidMail');
     }
     database::Query('SELECT * FROM users WHERE mail=:var1', array('var1' => $data['data']['mail']), $stats);
     if ($stats > 0) {
         $user->errmsg = Texter::get('user|registrationMailFail');
     }
     $loginCredentials = $user->createPassword($data['password']);
     if ($loginCredentials['success'] == 0) {
         $user->errmsg = $loginCredentials['errmsg'];
     }
     if ($data['password'] != $data['password2']) {
         $user->errmsg = Texter::get('user|passwordNotEqualFail');
     }
     if ($user->errmsg == '') {
         foreach ($data['data'] as $key => $val) {
             $user->set($key, $val);
         }
         $user->set('accesscode', $user->getAccessCode());
         $user->set('salt', $loginCredentials['salt']);
         $user->set('password', $loginCredentials['password']);
         $user->save();
         logging::log(1, $user);
     }
     return $user;
 }
<?php

logging::log(10, $_SESSION['user']);
session_destroy();
unset($_COOKIE['auth_cookie']);
setcookie('auth_cookie', null, -1, '/');
header('Location: login?reason=logout');
switch ($_POST['action']) {
    case 'saveData':
        $user = new user($_SESSION['user_id']);
        if (isset($_POST['values']['user'])) {
            foreach ($_POST['values']['user'] as $key => $val) {
                $user->set($key, $val);
            }
        }
        if (isset($_POST['values']['files'])) {
            foreach ($_POST['values']['files'] as $key => $val) {
                $user->files[$val['id']]['comment'] = $val['comment'];
            }
        }
        $user->save();
        logging::log(3, $user, $_POST['values']['user']);
        echo json_encode(array('status' => 1));
        break;
    case 'sendMessage':
        $return = $this->user->sendMessage($_POST['values']['text'], $_POST['values']['recipientId']);
        if ($return !== false) {
            echo json_encode(array('status' => 1, 'time' => date('d.m.Y H:i'), 'msgid' => $return, 'profilepic' => $this->user->get('profilepic'), 'username' => $this->user->get('firstname') . ' ' . $this->user->get('lastname')));
        }
        break;
    case 'chatinit':
        $return = '';
        $user = new user($_SESSION['user_id']);
        $RS = $user->getChat($_POST['values']['lastmsgid']);
        foreach ($RS as $key => $msg) {
            $RS[$key]['time'] = date('d.m.Y H:i', $msg['time']);
        }