I have a function called get_header() which includes the header file in a template (a bit like wordpress), which is working. Also defined in my functions file is a stylesheetURL() function which gets the template’s stylesheet url.
Inside my header.php file (in a subdirectory “design”), i’m calling stylesheetURL and PHP says it’s undefined.
This is the structure:
pagehandler.php – handles page requests. Includes ‘load.php’ and then ‘design/page.php’
load.php – includes ‘functions.php’ and classes.
functions.php – contains procedural functions like get_header and stylesheetURL. get_header actually includes the header.php file as an absolute url (http://website.com/design/header.php) inside the function, but because functions don’t have scope, it should still call the stylesheeturl function fine.
page.php – calls function get_header(), echos content, then calls get_footer().
header.php – calls stylesheetURL(). << This is where it breaks. The header file is included fine, but doesn’t have access to any of the functions.
Why is this happening?
EDIT:
// settings is a global array, and siteURL displays the url just fine if called from any file other than header.php or footer.php.
function siteURL() {
global $settings;
return $settings['site_url'];
}
function designURL() {
$siteurl = siteURL();
return $siteurl.'/design';
}
function stylesheetURL() {
$durl = designURL();
return $durl.'/style.css';
}
function get_header() {
$durl = designURL();
require $durl.'/header.php';
}
In fact, if I change from get_header() to include 'header.php' it works as expected.
I guess it is because, you can’t require files via an url. You need a path, not an url to require a file. Include is working if you have remote file inclusion set on in your php.ini.