Jump to content

[SOLVED] include in construct function


dumdumsareyum

Recommended Posts

I'm working on a login class. I am trying to send a file with settings to the constructor function, like this:

public function __construct($settings_file) {
		session_start();
		$this->connectToMySQL();
		//$this->checkUserIP();
		if(!isset($_SESSION['auth'])){
			$_SESSION['auth'] = 0;
		if(!include("$settings_file"))
		  throw new Exception("Unable to find settings");
		}
	}

 

The settings file contains the name of the database table etc. in form of $this->dbName = "dbName";

Before I was doing it this way, all my variables were just declared inside the class, but then I thought it would be nice to use the same class for regular accounts and administrator accounts and just include whichever file I wanted to change the db table and other settings for an admin. However, now it is not finding those variable values from the external file, and it doesn't throw the exception I have either shown here in the constructor, my queries are just returning exceptions and when I echo the variables in question they are null.....So, am I going about this wrong or what?

Link to comment
Share on other sites

Here is what the stuff in the file looks like

 

/*DABATASE TABLE*/
	$this->accountTable = "clients";

	/*path to redirect successful login to*/
	$this->login_success_path = "client.php";

	/*path to redirect a failed login to*/
	$this->login_failed_path = "client.php";

	/*path to page to process email verifications, using get input*/
	$this->verification_path = "verifyAcct.php";

	/*Do email accounts have to be verified before logging in?  0 = accounts do not need to be verified, 1 = accounts do need to be verified*/
	$this->using_verified = 1;

	/*Method of verification -- administrator confirmed = 0, user confirmed = 1
	  							Administrator emails account details to admin and they log in and approve/disprove.
	  							User confirmed emails user and has them confirm receipt of email*/
	$this->verification_method = 0;

 

which before i moved it just looked like

private $accountTable = "clients.php";

 

and now I declare

private $accountTable;

 

in the class

 

also, I tried echoing something, anything, from the constructor, should I be able to do that?

Link to comment
Share on other sites

No, it doesn't work without the quotes either unfortunately. The first error it gets to is where I am checking to see if the username exists. when I echo this query I get

 

SELECT * from WHERE username = ''

 

which is very strange to me too because the value that should be in the username is also now not appearing, and it is set from that function ($this->username = $username, and $username is a function parameter), and has nothing to do with the variables I am trying to include in the constructor but for some reason is now not working either.

Link to comment
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.