Eggzorcist Posted July 29, 2010 Share Posted July 29, 2010 Hi, I'm fairly new to OOP so please bare with me. I've been given to understand __construct is put forth in order to do that as soon as the object is created. Now I've created an object to control sessions. so here is my construct code includes a function within that object and session_start(). However, I get the error that the function within that object is non-existent but the function is right underneath the __construct function. should I put __construct last thing in my object? ANy help on this issue would be excellent! Thank you. Quote Link to comment Share on other sites More sharing options...
trq Posted July 29, 2010 Share Posted July 29, 2010 Post your code. Quote Link to comment Share on other sites More sharing options...
Eggzorcist Posted July 29, 2010 Author Share Posted July 29, 2010 class Sessions { public $logged_in = false; protected $username; protected $password; function __construct(){ session_start(); check_login(); } public function is_logged_in(){ return $this->logged_in; } public function check_login(){ if(isset($_SESSION['browser']) && $_SESSION['browser'] == $_SERVER['HTTP_USER_AGENT'] && isset($_SESSION['ip']) && $_SESSION['ip'] == $_SERVER['REMOTE_ADDR']){ if(isset($_SESSION['username'])){ $this->logged_in = true; } else { $this->logged_in = false; } } else { $this->logged_in = false; } } .... Quote Link to comment Share on other sites More sharing options...
trq Posted July 29, 2010 Share Posted July 29, 2010 Because check_login() is a method of the instantiated object, it needs to be referenced by $this->. So.... $this->check_login(); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.