Don't have an account? Register now to chat, post, use our tools, and much more.
Latest Headlines
Online Users
There are 113 users online: 7 members, 69 guests and 37 bots. Members: Ashbad, CalebHansberry, HOMER-16, rfdave, xologist. Bots: VoilaBot (1), Spinn3r (1), MSN/Bing (1), Magpie Crawler (3), VoilaBot (10), Googlebot (20), MSN/Bing (1).
RSS & Social Media
SAX
You must log in to view the SAX chat widget
|
| Author |
Message |
|
comicIDIOT

Guru

Joined: 01 May 2006 Posts: 5108 Location: SFBA, California
|
Posted: 27 Mar 2012 04:02:42 am Post subject: $_GET in a CSS File Issue |
|
|
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;
}
_________________
-Alex |
|
| Back to top |
|
|
benryves

Cemetech Expert

Joined: 12 Aug 2008 Posts: 1359 Location: London, United Kingdom
|
Posted: 27 Mar 2012 05:40:54 am Post subject: |
|
|
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. |
|
| Back to top |
|
|
comicIDIOT

Guru

Joined: 01 May 2006 Posts: 5108 Location: SFBA, California
|
Posted: 27 Mar 2012 07:36:28 pm Post subject: |
|
|
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. _________________
-Alex |
|
| Back to top |
|
|
elfprince13

OVER NINE THOUSAND!

Joined: 23 May 2005 Posts: 10234 Location: A galaxy far far away......
|
|
| Back to top |
|
|
|
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
|
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
|
© Copyright 2000-2013 Cemetech & Kerm Martian :: Page Execution Time: 0.029574 seconds.
|