html5 - php Illegal offset type in isset or empty -
i have code working initially, not work after restarted computer.
the error getting is:
warning: illegal offset type in isset or empty in d:\xampp\htdocs\cookieboylive\classes\session.php on line 4
there's 3 files on site - index, login, register. index page checks if users logged in, don't think has problem.
here's current code:
the main register/login.php page
require_once 'core/init.php'; if(input::exists()) { if(token::check(input::get('token'))) { $validate = new validate(); $validation = $validate->check($_post, array( 'username' => array('required' => true), 'password' => array('required' => true) )); if($validation->passed()) { $user = new user(); $login = $user->login(input::get('username'), input::get('password')); if($login) { redirect::to('index.php'); } else { echo '<p>sorry, login failed.</p>'; } } else { foreach($validation->errors() $error) { echo $error, '<br>'; } } } } if(input::exists()) { if(token::check(input::get('token'))) { $validate = new validate(); $validation = $validate->check($_post, array( 'username' => array( 'required' => true, 'min' => 2, 'max' => 20, 'unique' => 'users' ), 'password' => array( 'required' => true, 'min' => 6 ), 'password_again' => array( 'required' => true, 'matches' => 'password' ), 'name' => array( 'required' => true, 'min' => 2, 'max' => 50 ) )); if($validation->passed()) { $user = new user(); $salt = hash::salt(32); try { $user->create(array( 'username' => input::get('username'), 'password' => hash::make(input::get('password'), $salt), 'salt' => $salt, 'name' => input::get('name'), 'joined' => date('y-m-d h:i:s'), 'group' => 1 )); session::flash('home', 'register success'); redirect::to('index.php'); } catch(exception $e) { die($e->getmessage()); } } else { foreach($validation->errors() $error) { echo $error, '<br>'; } } } } ?> <!doctype html> <html> <head> <meta http-equiv="x-ua-compatible" content="ie=edge,chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" type="text/css" href="styles/register_login_styles.css"> <link rel="stylesheet" type="text/css" href="styles/animate-custom.css"> </head> <body> <div class="container"> <div id="container_demo" > <a class="hiddenanchor" id="toregister"></a> <a class="hiddenanchor" id="tologin"></a> <div id="wrapper"> <div id="login" class="animate form"> <form action="" method="post"> <div class="field"> <h1>log in</h1> <p> <label for="username" class="uname" data-icon="u" >username </label> <input id="username" name="username" required="required" type="text" placeholder="username" autocomplete="off"> </p> <p> <label for="password" class="youpasswd" data-icon="p">password </label> <input id="password" name="password" required="required" type="password" placeholder="password"> </p> <p class="keeplogin"> <input type="checkbox" name="loginkeeping" id="loginkeeping" value="loginkeeping"> <label for="loginkeeping">keep me logged in</label> </p> <input type="hidden" name="token" value="<?php echo token::generate(); ?>"> <p class="login button"> <input type="submit" value="login"> </p> <p class="change_link"> not member yet ? <a href="#toregister" class="to_register">join us</a> </p> </form> </div> </div> <div id="register" class="animate form"> <form action="" method="post"> <h1> sign </h1> <p> <label for="username" class="uname" data-icon="u">username</label> <input id="username" value="<?php echo escape(input::get('username')); ?>" name="username" required="required" type="text" placeholder="username" autocomplete="off"> </p> <p> <label for="password" class="youpasswd" data-icon="p">your password </label> <input id="password" name="password" required="required" type="password" placeholder="password"> </p> <p> <label for="password_again" class="youpasswd" data-icon="p">please confirm password </label> <input id="password_again" name="password_again" required="required" type="password" placeholder="password again"> </p> <p> <label for="name" class="youmail" data-icon="n" >name</label> <input id="name" name="name" value="<?php echo escape(input::get('name')); ?>" required="required" type="text" placeholder="name" autocomplete="off"> </p> <input type="hidden" name="token" value="<?php echo token::generate(); ?>"> <p class="signin button"> <input type="submit" value="sign up"> </p> <p class="change_link"> member ? <a href="#tologin" class="to_register"> go , log in </a> </p> </form> </div> </div> </div> </div> </body> </html>
session.php
<?php class session { public static function exists($name) { return (isset($_session[$name])) ? true : false; } public static function put($name, $value) { return $_session[$name] = $value; } public static function get($name) { return $_session[$name]; } public static function delete($name) { if(self::exists($name)) { unset($_session[$name]); } } public static function flash($name, $string = '') { if(self::exists($name)) { $session = self::get($name); self::delete($name); return $session; } else { self::put($name, $string); } } }
user.php
<?php class user { private $_db, $_data, $_sessionname, $_isloggedin; public function __construct($user = null) { $this->_db = db::getinstance(); $this->_sessionname = config::get('session/session_name'); if(!$user) { if(session::exists($this->_sessionname)) { $user = session::get($this->_sessionname); if($this->find($user)) { $this->_isloggedin = true; } else { // pr0cess logout } } else { $this->find($user); } } } public function create($fields = array()) { if(!$this->_db->insert('users', $fields)) { throw new exception('there problem creating account.'); } } public function find($user = null) { if($user) { $field = (is_numeric($user)) ? 'id' : 'username'; $data = $this->_db->get('users', array($field, '=', $user)); if($data->count()) { $this->_data = $data->first(); return true; } } return false; } public function login($username = null, $password = null) { $user = $this->find($username); if($user) { if($this->data()->password === hash::make($password, $this->data()->salt)) { session::put($this->_sessionname, $this->data()->id); return true; } } return false; } public function data() { return $this->_data; } public function isloggedin() { return $this->_isloggedin; } }
i tried of solutions suggested above. in actual fact answer not in spelling in fact that, pointed out above, $name variable in exists function array.
public static function exists($name) { return (isset($_session[$name])) ? true : false; }
the simple fix append [0] [$name] becomes [$name][0] returns value associated , 1 want see. works me. why worked in video, can't figure out; may configuration thing.
Comments
Post a Comment