У меня есть еще одна проблема с login.php, если я хочу войти в систему, и у меня есть «запомнить меня», но все проверено. Но когда я его не проверял, я получаю эту ошибку.OOP система регистрации/регистрации
Я новичок в php, и я использую эту систему для второстепенного курса, поэтому я знаю, что он уже старый, но мне бы очень хотелось закончить его. Я изучаю этот способ.
Примечание: Undefined переменной: hashCheck в C: \ WAMP \ WWW \ websitegroop \ классы ">" \ user.php на линии 63 Call Stack
1 0,0006 255552 {главная}() .. \ Логин .php: 0 2 0,0094 386832 user-> Логин() .. \ login.php: 25
и:
Фатальная ошибка: Вызов функции подсчета член() на не-объект в C : \ wamp \ www \ websitegroop \ classes \ user.php в строке 63 Стол вызовов
1 0,0006 255552 {главная}() .. \ login.php: 0 2 0,0094 386832 User-> Логин() .. \ login.php: 25
Вот мой код:
Войти .php
enter code here <?php
require_once 'core/init.php';
if(Session::exists('login')) {
echo '<p>' . Session::flash('login') . '<p>';
}
if(Input::exists()) {
if(Token::check(Input::get('token'))) {
$validate = new Validate();
$validation = $validate->check($_POST, array(
'gebruikersnaam' => array('required' => true),
'paswoord' => array('required' => true)
));
if($validation->passed()) {
$user = new User();
$remember =(Input::get('remember') === 'on') ? true: false;
$login = $user->login(Input::get('gebruikersnaam'), Input::get('paswoord'), $remember);
if($login) {
Redirect::to('index.php');
} else {
echo '<p> Sorry het is niet gelukt om in te loggen. </p>';
}
} else {
foreach($validation->errors() as $error) {
echo $error, '<br>';
}
}
}
}
?>
hash.php
enter code here <?php
class Hash {
public static function make($string, $salt = '') {
return hash('sha256', $string . $salt);
}
public static function salt($length) {
return mcrypt_create_iv($length);
}
public static function unique() {
return self::make(uniqid());
}
}
user.php
enter code here <?php
class User {
private $_db,
$_data,
$_sessionName,
$_cookieName,
$_isLoggedIn;
public function __construct($user = null) {
$this->_db = Database::getInstance();
$this->_sessionName = Config::get('session/session_name');
$this->_cookieName = Config::get('remember/cookie_name');
if(!$user) {
if(Session::exists($this->_sessionName)) {
$user = Session::get($this->_sessionName);
if($this->find($user)) {
$this->_isLoggedIn = true;
} else {
}
} else {
} $this->find($user);
}
}
public function create($fields = array()) {
if(!$this->_db->insert('groopklanten', $fields)) {
throw new Exception('Er is een probleem met het maken van een account.');
}
}
public function find($user = null) {
if($user) {
$field = (is_numeric($user)) ? 'id' : 'gebruikersnaam';
$data = $this->_db->get('groopklanten', array($field, '=', $user));
if($data->count()) {
$this->_data = $data->first();
return true;
}
}
return false;
}
public function login($gebruikersnaam = null, $paswoord = null, $remember) {
$user = $this->find($gebruikersnaam);
if($user) {
if($this->data()->paswoord === Hash::make($paswoord, $this->data()->salt)) {
Session::put($this->_sessionName, $this->data()->id);
if($remember) {
$hash = Hash::unique();
$hashCheck = $this->_db->get('users_session_table', array('user_id', '=', $this->data()->id)); }
if(!$hashCheck->count()) {
$this->_db->insert('users_session_table', array(
'user_id' => $this->data()->id,
'hash' => $hash
));
} else {
$hash = $hashCheck->first()->hash;
}
Cookie::put($this->_cookieName, $hash, Config::get('remember/cookie_expiry'));
}
return true;
}
return false;
}
public function logout() {
Session::delete($this->_sessionName);
}
public function data() {
return $this->_data;
}
public function isLoggedIn() {
return $this->_isLoggedIn;
}
}
init.php
enter code here <?php
session_start();
$GLOBALS['config'] = array(
'mysql' => array(
'host' => 'localhost',
'username' => 'nick16061983',
'password' => 'N1sn0p1!A',
'db' => 'websitegroop'
),
'remember' => array(
'cookie_name' => 'hash',
'cookie_expiry' => 604800
),
'session' => array(
'session_name' => 'groopklanten',
'token_name' => 'token'
)
);
spl_autoload_register(function($class) {
require_once 'classes/' .$class. '.php';
});
require_once 'functions/sanitize.php';
Я надеюсь, что я предоставил достаточно информации.
Спасибо заранее,
Ник
omg i полностью упустил из виду фигурную скобку ...... спасибо, что не помню, в следующий раз, когда мне нужно использовать ползунок, чтобы проверить, есть ли что-то там .... –