We've added classes for articles and users each of which have a corresponding table in the database.
However classes don't have to necessarily have a database table associated with them here in the off
include We're declaring a function that returns whether a user is logged in or not.
Let's move this into a class instead which will allow us to argue now is our code better.
Let's create a new class file in the classes folder called off P H.
P..
The class will be called off.
And let's take this function out of the arfe include
and paste it in the new off class.
This will be a public method and were not going to create an object of this class so I will make it
static too.
And let's not forget to add a p-h P duck comments block to our class.
We're calling the is logged in function from the index page.
Let's change this to call the is logged in method of the arfe class instead first will change this require
to load the class instead of the includes file and then when we call the function we'll prefix it with
the class name which will call the static method.
Let's give that a try the message and links shown on the index page at different depending on whether
we logged in or not.
Were not currently logged in and if I do log in
the message changes as expected.
We're also calling the is logged in function on the new article page here so let's do the same.
Change the Require to the class and prefix the method call with the class name.
The method is called In the new article script to restrict access to the page.
If the use isn't logged in.
We're currently logged in so we can access the page if I log out the link isn't shown but if I enter
the U R L directly.
We're denied access to the page so this is working as before
and now we've replaced this after P XP script in the includes folder with the class.
We can safely delete it.