To send an email in the contact page were using an S M T P server.
The settings for this server and the host username password and so on are in the contact page script.
When we connect to the database we also need credentials such as the host user name and password and
these are currently in the Database class.
When we copy our cold live to a production server these credentials will no doubt change.
It would be easier if we had all the values that change in a separate file.
That creates a new file in The Root kalid config up HP.
In here.
Will store any configuration settings that change between different environments developments on your
local machine production on your life server and so on.
This way we only need to change this one file when moving between servers.
We learnt early Iran how to define global constants using the defined function.
So this is what will use for each conflict setting.
Let's start with the database settings.
We have four settings for the host database name using name and password.
Let's create for equivalent constants for those values in the Conficker script.
Now as these constants are globally available we could just use them inside the Database class here.
However that would be making this class dependent on those global variables which is generally a bad
practice.
Whenever we want to use the database connection we are creating a new database object and calling the
get conned method in the includes dbe file here.
So let's use the global constants in here instead.
The database credentials make sense as properties of a database object.
So first let's add properties for each of these to the class.
Then we can set these properties when we create a new database object.
So let's add a constructor method.
With arguments for each property.
Then in the body of this method set the property values to the values of the arguments.
Then in the get conned method we can remove these variables and use the property values instead.
When we create the DSN variable and the new P.D.A object.
Then when we create a new database object we pass in the constants we created in the new config file.
Finally we need to include the config file in our code.
We're including this init script in all our scripts.
So let's do it in here.
Let's give that a try.
The index page is still working and this is reading from the database.
So the database credentials are being read successfully from the config file.
It seems we've broken the admin page however.
This is because we need to require this file relative to this one as we did with requiring classes in
the ATA louder.
So let's do the same for the config file.
And now when we go to the addleman area it works.
Let's also take these mail server credentials out of the contact page let's create constants for the
host username and password.
Then in the contact page use these constants instead of the values directly.
If there are other values in here that you want to change between servers for example the port are the
sender address then you can put those in the config file to in the same way the same goes for any values
that you want to differ between servers.
So there are all in the same place in one configuration file.