one thing I noticed, when using include I can only access the included files functions from the file that included it. With require_once, I can run that function in a second required_once file.
also: I recommend adding
if(file_exists($RequiredFile)){
require_once($RequiredFile);
}else{
die('Error: File Does Not Exist');
}
Because when require_once kills the page, it can sometimes echo the directory of your website files
Here's a custom function I made to require files:
function addFile($file, $type = 'php', $important=false){
//site-content is a directory where I store all the files that I plan to require_once
//the site-content directory has "deny from all" in its .htaccess file to block direct connections
if($type && file_exists('site-content/'.$file.'.'.$type) && !is_dir('site-content/'.$file.'.'.$type)){
//!is_dir checks that the file is not a folder
require_once('site-content/'.$file.'.'.$type);
return 'site-content/'.$file.'.'.$type;
}else if(!$type && file_exists('site-content/'.$file) && !is_dir('site-content/'.$file)){
//if you set "$type=false" you can add the file type (.php, .ect) to the end of the "$file" (useful for requiring files named after changing vars)
require_once('site-content/'.$file);
return 'site-content/'.$file;
}else if($important){
//if you set $important to true, the function will kill the page (which also prevents accidentally echoing the main directory path of the server)
die('Server Error: Files Missing');
return false;
}else{
//the function returns false if the file does not exist, so you can check if your functions were successfully added
return false;
}
}
usage example:
$success = addFile('functions/common');
if($success){
commonFunction();
}else{
fallbackFunction();
}