PHP in CSS einbinden ?

Yonnyy

Mitglied
Hallo Leute, ich möchte gerne PHP in meine CSS einbinden.
Also habe ich eine style.php erstellt und am anfang
PHP:
<?php
    header('Content-type: text/css'); 
?>
geschrieben, sowie in der Index.php den style auf style.php verlinkt habe.
HTML:
    <link href="style.php" type="text/css" rel="stylesheet" />
Am Anfang der Index habe ich noch folgendes geschrieben:
PHP:
<?php

ob_start ();

?>

und am Ende noch:
PHP:
<?php

ob_end_flush ();

?>

Und dann lädt der keine style mehr .... Wieso nicht ?
Kann mir jemand helfen? Danke schon mal im Vorraus.
MFG Yonnyy
 
Hi Yonnyy,

gibt es denn eine style.php, die CSS-Code produziert?
Schau dir mal den HTTP-Trafic im Browser an (F12 drücken und eventuell neu laden).

Grundsätzlich:
CSS kann nicht in PHP eingebunden werden!
PHP erzeugt Code
so:
PHP:
echo '<link href="style.php" type="text/css" rel="stylesheet" />';
(innerhalb des headers!)
Der Browser bekommt dann das:
HTML:
<link href="style.php" type="text/css" rel="stylesheet" />
Dann lädt der Browser die Datei style.php.

Ich hoffe dir ist das jetzt etwas klarer,
javaDeveloper2011
 
Ne kapier ich immer noch nicht so ganz, aber es wird auf jeden Fall kein style geladen(F12).
Könntest du das bitte nochmal erklären?

Yonnyy
 
Ich habe folgendes minimale Beispiel erstellt:

index.html
HTML:
<!DOCTYPE html>
<html>
	<title>CSS PHP</title>

	<link href="style.php" rel="stylesheet" type="text/css" />

	foobar
</html>

style.php
PHP:
<?php
	header('Content-type: text/css');
?>

html {
	color:red;
	font-weight: <?php echo 'bold'; ?>;
}


Der Text ist sowohl rot als auch fett. Man kann beides also ohne Probleme mischen. Dein Problem muss woanders liegen.
 
Meine style.php sieht so aus:
Code:
<?php
    header('Content-type: text/css');

    $filebg = "options\\settingsbg.php";
    $fsettingsbg = fopen($filebg, "r");
    $bg = fread($fsettingsbg, filesize($filebg));
    fclose($fsettingsbg);
    if($bg=='3') {
        $bgcss = 'background: #768E1D';
    }
    else {
        $bgcss = 'background: url(layouts/bg<?php echo $bg; ?>.jpg);'
    }
?>
body {
    margin: 0px;
    padding: 0px;
    <?php echo $bgcss; ?>
    font-family: "Trebuchet MS",Verdana,sans-serif;
    color: #161414;
}

.header {
    background: url(layouts/c0db5a/header.jpg) repeat-x;
    height: 43px;
    width: auto;
    padding: 0px;
}

.headerbuttom {
     box-shadow-buttom: 0 1px 2px rgba(0, 0, 0, 0.3);
    -webkit-box-shadow-buttom:  0 1px 2px rgba(0, 0, 0, 0.3);
    -moz-box-shadow-buttom:  0 1px 2px rgba(0, 0, 0, 0.3);
}

.logo {
    background: url(layouts/logo.png) no-repeat;
    height: 35px;
}

.content {
    padding: 0px;

}

.contentmid {
    padding: 5px;
    width: 1000px;
    margin: 0px auto;
    margin-bottom: 5px;
    background: #DDEDA0;
    -moz-border-radius-bottomleft: 8px; /* Firefox */
    -webkit-border-radius-bottomleft: 8px; /* Safari, Chrome */
    -khtml-border-radius-bottomleft: 8px; /* Konqueror */
    -border-radius-bottomleft: 8px; /* CSS3 */
    -moz-border-radius-bottomright: 8px; /* Firefox */
    -webkit-border-radius-bottomright: 8px; /* Safari, Chrome */
    -khtml-border-radius-bottomright: 8px; /* Konqueror */
    -border-radius-bottomright: 8px; /* CSS3 */
    -box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    -webkit-box-shadow:  0 1px 2px rgba(0, 0, 0, 0.3);
    -moz-box-shadow:  0 1px 2px rgba(0, 0, 0, 0.3);
    border-color: #161414;
}

.navi {
    border-bottom: #cae469 2px;
}

.button {
    margin: 0px auto;
    text-decoration: none;
    font-family: "Trebuchet MS",Verdana,sans-serif;
    font-weight: bold;
    font-size: 120%;
    color: #161414;
    border-color: #768E1D;
    background: #DDEDA0;
    -moz-border-radius-bottomleft: 8px; /* Firefox */
    -webkit-border-radius-bottomleft: 8px; /* Safari, Chrome */
    -khtml-border-radius-bottomleft: 8px; /* Konqueror */
    -border-radius-bottomleft: 8px; /* CSS3 */
    -moz-border-radius-bottomright: 8px; /* Firefox */
    -webkit-border-radius-bottomright: 8px; /* Safari, Chrome */
    -khtml-border-radius-bottomright: 8px; /* Konqueror */
    -border-radius-bottomright: 8px; /* CSS3 */
    padding: 5px;
    padding-left: 93px;
    padding-right: 93px;
}

.button:hover {
    background: #cae469;
    text-decoration: none;
}

.submit {
    background: #c0db5a;
    border: #161414 2px;
    -moz-border-radius: 8px; /* Firefox */
    -webkit-border-radius: 8px; /* Safari, Chrome */
    -khtml-border-radius: 8px; /* Konqueror */
    -border-radius: 8px; /* CSS3 */
    font-weight: bold;
}

.footer {
    margin: 0px auto;
    text-align: center;
    text-decoration: none;
    color: #000000;
}

.footer a, a.footer:visited {
    text-decoration: none;
    color: #000000;
}

.error {
    background: url(error.png);
    height: 127px;
    width: 467px;
    margin: 0px auto;
}

.login {
    -moz-border-radius: 8px; /* Firefox */
    -webkit-border-radius: 8px; /* Safari, Chrome */
    -khtml-border-radius: 8px; /* Konqueror */
    -border-radius: 8px; /* CSS3 */
    -box-shadow-buttom: 0 1px 2px rgba(0, 0, 0, 0.3);
    -webkit-box-shadow-buttom:  0 1px 2px rgba(0, 0, 0, 0.3);
    -moz-box-shadow-buttom:  0 1px 2px rgba(0, 0, 0, 0.3);
    background: #c0db5a;
    padding: 5px;
    margin: 0px auto;
    margin-top: 50px;
    width: 293px;
}

.login1 {
    margin: 0px auto;
    text-align: center;
}

.add{
    border-color: #C0DB5A;
    border-style: solid;
    border-width: 1px;
    margin: 5px 0px;
    padding: 0px 0px 0px 5px;
    height: 55px;
    width: 175px;
    background: #484848;
}

.add:hover {
    background-color: #555555;
}

.add strong {
    color: #FFFFFF;
    font-family: "Trebuchet MS", Verdana, sans-serif;
    font-size: 2.25em;
    margin-bottom: 5px;
}

.add em {
    color: #C0DB5A;
    font-style: normal;
}

.add ul {
    margin: 5px;
}

Eigentlich sollte es doch funktionieren, oder ?
 
Zurück