Forum Moderators: coopster
$section1="FF0000";
$section2="00FF00";
$section3="0000FF";
$section4="FFFF00";
$section5="00FFFF";
Each section is under a different subfolder in the site root:
www/section1/
www/section2/
www/section3/
www/section4/
www/section5/
What I want is for a page in any section's subfolder to dynamically be colored. So if I put page test.php in section1 subfolder it would be colored #FF0000 (red) but if I moved it to section4 subfolder it would be colored #FFFF00 (yellow).
I think what I need is PHP_SELF but am not sure how to strip that down to reflect only the subfolder. Then once I have that subfolder, I'm not really sure how use it to pull from my included file colors.php.
If I can be any clearer--please let me know. I thank you in advance for your help and patience with a PHP novice!
It took a little configuring, but that code worked like a charm.
Here's what I ended up doing:
In file color_config.php:
function back_color($url) {
$filename = $_SERVER['PHP_SELF'];
$folder = substr($filename, 0, strrpos($filename, '/'));
if ($folder == "/subfolder"){
$color = "#FF0000";
}
...and so on--with an IF statement for each section.
Within each of my actual webpages I placed:
<?php include "../includes/color_config.php"?>
and wherever I wanted the color to print, something like this:
bgcolor="<?php print back_color($url);?>"
Thought I'd include that in case anyone would be interested?