My header.php looks like this.
include("sessions.php");
<h1>...
My sessions.php page looks like this
session_start();
function validate_user()
{
//validate user
}
I have a user_class.php in my body. can i just call validate_user() because i have already included it in the page or do i have to include it in my user_class.php and every .php that uses a session function?
Short answer, yes. What your asking is essentially the whole purpose of includes. Using includes you can divide you code into chunks (files) that represent functional units, such as your session handling. As some of the other posters have suggested, one of your chunks might be your initialization code.
Imagine includes as simply inlining the file into the point of the include/require statement, replacing it. In this model, as long as the function would appear above the point you are using it, you’re good to go.
At the end of the day, it’s you preference on how you divide up your code but books like the classic “Design Patterns” from the Gang of Four can help you make good decisions about how to design your code for maximum ease of maintenance and re-use.