My site uses a .PHP file as it's CSS, with great success. However, I'm trying to make a new addition and I'm having extreme difficulty. I'd like to adjust how the visitor views the page depending on which variables are set (i.e. ?ref=cemetech). I figured I'd be able to include another file within my CSS for such things. So, I have getget.php & colors.php linked within my CSS like so.


Code:
<?php

   header("Content-type: text/css");
   include('../inc/getget.php');
   include('../inc/colors.php');

?>


Actually, at the moment I have a duplicate for the header but it's contents are as follows:


Code:
<?php

   include('getget.php');

   if(is_file($refimg)) {
      echo '<!-- Is File -->';
   }
   
   if (!$img) {
      echo '<!-- Not Set -->';
   } else {
      echo '<!-- Is Set: ' . $refimg .' -->';
   }
   
?>


I can't get the same to work for the CSS. If you browse to an image within my portfolio, for example, you match all the criteria needed and you get the echoes on lines 5 and 6 of the page HTML but in the CSS, starting on Line 2 I don't get anything for the background image except the path I hard coded to the variable.

Is there a limitation with CSS that doesn't allow $_GET calls? Or any variables to pass to it? As I even tried removing the include from the CSS file and the line for the background image doesn't even show up, despite the headers include coming before the CSS, as you'll note from the page source.

I tried Googling but the only results I find are for getting the headers sent by the browser. I found this result, but that's a little bit out of my understanding for now. Currently, my CSS looks something like:


Code:
#nav a:hover {
   background: <?=$maincolordark?> url(../img/topgradr.png) center bottom;
}
You aren't passing a query string to the stylesheet:


Code:
<link rel="stylesheet" type="text/css" media="screen" title="Standard Style" href="/res/css/style.php">


Each HTTP request the browser makes is independent and won't automatically inherit the query string of the referring page. You can append it manually:


Code:
<link
    rel="stylesheet"
    type="text/css"
    media="screen"
    title="Standard Style"
    href="/res/css/style.php?<?php echo htmlspecialchars($_SERVER['QUERY_STRING'], ENT_QUOTES); ?>"
>


Note that <?= is not a good thing to rely on as it can be disabled and as such might not be available on a server you deploy to - use "<?php echo" instead.
Interesting. That's good to know, thanks!

I used <?= from an example I saw online. I'll go through and change those to proper openings and echos though.
comicIDIOT wrote:
I used <?= from an example I saw online.


Just go here: http://www.w3schools.com/php/
Many PHP "tutorials" teach atrocious habits. Like <?=
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement