PHP Works in Some Parts of a Page, But Not Others?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dsmith21212
Forum Newbie
Posts: 1
Joined: Thu Jul 23, 2009 9:27 am

PHP Works in Some Parts of a Page, But Not Others?

Post by dsmith21212 »

:crazy:
I have this line of code in header.php which allows a website owner to specify a color scheme through a configuration file.

Code: Select all

<link rel="stylesheet" type="text/css" href="<?php echo $cbvurl ?>styles/<?php echo $cbvstyle ?>.css" />
I'm running into two problems.

1. In most pages, the style displays properly. In others, no style at all.
View Source shows this:

Code: Select all

<link rel="stylesheet" type="text/css" href="styles/.css" />
2. On pages where this does not work,

Code: Select all

<?php echo $cbvurl ?>
does work in other parts of the same page (main menu). (strange = in some parts of the site, this tag needs a trailing slash, but not in others...)

All pages have the .php file extension and headers are called by include statement. (XAMPP)
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: PHP Works in Some Parts of a Page, But Not Others?

Post by cpetercarter »

If the source code reads :

Code: Select all

<link rel="stylesheet" type="text/css" href="styles/.css" />
then obviously the script is unable to find values for $cbvurl and $cbvstyle.

You will need to go through the logic of your code carefully to find out why. Perhaps the code which defines $cbvurl and $cbvstyle runs after the code which writes the head section of the web page. Or perhaps the two variables have limited scope (eg they exist within a function, but not outside it).
Post Reply