Jump to content

__construct issue


Eggzorcist

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/209198-__construct-issue/
Share on other sites

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;	
}
}

....

Link to comment
https://forums.phpfreaks.com/topic/209198-__construct-issue/#findComment-1092492
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.