I am creating a dynamic website using PHP, which includes a user login system. There is a script in every page which checks whether the user is logged in (using cookies). If not, he is redirected to the login page. Since this script is exactly the same for every page, I am thinking of creating a separate file for it, and including that file in every page. That will make it easy to manage and make changes, if required.
My question is does "including" (using the include
or require
statement) the file make the execution of my main page slower? Does it have other disadvantages? Let me mention at this point that I am currently on a free host.
Also, I have already created a page (databaseDetails.php) where I am storing my database name, username and password in variables; and I am referring to it every time a page loads. So if the answer to the first part of my question is yes, then my main page (main.php, which the user will actually view) will include the checkWhetherLoggedIn.php (which checks if the user is logged in), which in turn will be including the databaseDetails.php.
Is such a sort-of-"nested including" okay? Or should it be avoided?