1

Okay, so I've done a bit of research into using PHP to allow using variables in CSS. I know it'll have a hit on the performance, but that doesn't bother, what bothers me is that I can't get the PHP stylesheet to work as it should.

I'm linking the stylesheet with the following code

<link rel="stylesheet" type="text/css" media="screen" href="/res/css/default.php">

And in the PHP stylesheet I'm using the header to read the text as CSS:

<?php header("Content-type: text/css"); ?>

However I'm not getting the results I want at all, you can see the the problem by going to my website, www.andysinventions.info.

Checking the site in Google Chrome with the console open displays this error too,

"Resource interpreted as Stylesheet but transferred with MIME type text/plain." If anyone could explain to me what this meant it might help me resolve the issue.

If there's anything else you need, let me know and I'll fetch it for you if I can.

Thank you, Andy.

-

Got to go for now, however I will be back later to check answers/solutions.

0

4 Answers 4

7

When I go to http://www.andysinventions.info/res/css/default.php I get to see the PHP code. That means it's not getting parsed.

Sign up to request clarification or add additional context in comments.

6 Comments

Yep, beat me to it! Andrew, you might need to set something up in your web server to ensure it is run through the PHP interpreter. Or, rename it to have ".php" on the end.
I have editted the link to only look for default.php, and saved the file as default.php, so there shouldn't be a problem with the file extension.
Can you copy the file to the root directory? So it can be accessed on andysinventions.info/css.php
It's now accessible from andysinventions.info/default.php
Ok, there are two problems. One is a syntax error in your file, the other is PHP not being parsed in that directory. Did you make the directory yourself or did it exist already? Is all code from the website your own or do you use a CMS?
|
3

You must either configure your web server to interpret files ending with .css as PHP or rename your file to /res/css/default.php

2 Comments

There's a mistake in the question, the actual file is /res/css/default.php
The file is saved as default.php
1

When you open the stylesheet in your browser, you get to see the PHP code:

<?php header("Content-type: text/css"); ?>
<?php
$primary = 'orange';
$secondary = 'rgb(55,55,55)';
$trim = 'white';
?>
/*Main*/
*, html{
margin:0;
padding:0;
font-family: arial;
}

Somehow the stylesheet is not interpret as PHP code. Maybe you have an htaccess file that prevents this?

3 Comments

Options +Indexes ErrorDocument 404 /404.php Is everything that's in my .htaccess file, should I need to add something to that to fix it?
@AndrewFairbairn Do you have .htaccess files in your /res/ or /res/css/ folders?
.htaccess is in the root directory only.
0

Its getting read in at runtime as a css file not a php file so your server is never processing the php. That link line is getting read by the client's browser and the client machine is making another request for what it thinks is a flat css file and that's what its getting whether you have php in it or not.

I've never done this but I would think you'd have to use an include or a require to get closer to the results that you're looking for.

2 Comments

Would there be a way, using .htaccess, to tell the server to process the file as php before it's read as plain text?
Not that I am aware of but its a possibility.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.