Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.