I have a class where I want to use an API, and I've got the api keys in a separate file in another directory.
The api key file is literally as simple as this:
$id = 'xxxxxxx';
$key = 'xxxxxxx';
This doesn't work:
include '/path/to/file-with-api-keys.php';
class MyApiClass {
public function __construct($id, $token) {
$this->client = new Client($id, $token);
}
}
The code where I instantiate the class is in another php file I'm using to test, and it's extremely simple, just includes the class and then instantiates it:
include '/path/to/MyClass.php';
$result = new MyClass();
$result->myMethod();
echo $result;
The error I get is basically saying the 2 variables are null.
TWO QUESTIONS:
1) How can I access the value of the variables in my constructor? I've read elsewhere that using an include file directly in the method is bad practice, and also that using a global variable would be bad practice as well.
2) Somewhat related question, these files where I'm storing the api keys are in the same directory with my database connection details, but the directory is not outside the root. In this directory I have an .htaccess file with "Deny From All". Is this sufficient from a security standpoint, or should I do something else?
ok 3 questions...
3) Should I even bother keeping the api keys in separate files within this directory or just embed them into my class?
Hoping someone can give me best practices here. Thanks!