One function is Securelogin() that checks if the user is logged in.
My page consist of the following files
Header.php
Menu.php
Footer.php
Index.php
and some other files
Now my code in the Index.php is like the following:
blah blah
include 'functions.php';
blah blah
Securelogin();
Check if user == Logged in { //else bugg off
<div id=container>
include ' Header.php'
include 'Menu.php'
include 'Footer.php'
<div>
So if I want to protect the content in my header, footer, menu .php (which I want) I start the page with something like
Header.php
Securelogin();
check if user == Logged in {
echo 'Hi Im a lame header';
}
So the function in the header works if the header is loaded through index.php (since the index.php include the function.php that contains Securelogin() )
I know I should add include function.php to the header file but my qusetion is:
Now if I just try to copy paste the link directly to header.php I get an error and the Header.php is not displayed. This is ofcourse due to I'm calling a function that is not defined since i didnt include it.
Do I have to include functions.php in the headerfile or is it just as secure without the include since the page "crashes" without the include or is there a way to display the code when a page crashes... The browser says something like the file is not found or may contain an error...
My guess is that on my current server both options are both secure but by crashing the page I'm reliant upon a good serverconfiguration so the best practice is to do the include even in the headerfile since I can export the page to a different server with perhaps other settings and still maintain security.
So what do You guys say?
Also if I use include in index.php and then include the same file in header, menu and footer will it load the file 4 times (using up memory) or will it skip the include if the file is already included before... or should i use include once.. I heard include is faster than include once (not that I guess I will notice any difference in my application but which is the best practice? Include in index and include once in header menu and footer or include once in the index too...?
Thanks for taking time to answer this noob