Updating Included CSS File in header
app dir
css
style.css
inc
header.inc.php
footer.inc.php
index.php
login.php
register.php
style.css is included in the header.inc.php
<?php
//Include a error reporting:
include '../../errorReport.inc.php';
// Set default timezone:
define('TZ', date_default_timezone_set('America/Los_Angeles') );
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>
<?php
if(defined('TITLE'))
{
print TITLE;
} el开发者_运维技巧se {
print 'Raise High the Roof Beam! A J.D. Salinger Fan Club';
}
?>
</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="./c/screen.css" media="screen,projection" />
</head>
Upon creating a new page(login.php) the goal is adding styles to the include(d) CSS in the header. Not simply placing the css anywhere in the mark-up, the following is my attempt, it has failed:
<?php
header('content-type:text/css', replace);
header("Expires: ".gmdate("D, d M Y H:i:s", (time()+900)) . " GMT");
$errorColor = '#900';
echo '.error{ color: '.$errorColor.'; }';
?>
<?php include 'inc/header.inc.php';?>
<p class=\"error\">Error MSG</p>
<?php include 'inc/footer.inc.php';?>
This is printed to the UA:
.error{ color: #900; }
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>
Raise High the Roof Beam! A J.D. Salinger Fan Club </title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="./c/screen.css" media="screen,projection" />
</head>
<body>
<div id="wrapper">
.................................
The simple answer is that you should include this CSS in your style sheet, style.css, because it is constant.
If you want this to be dynamic, you will need to modify your scheme a bit. This is where a framework would be helpful because any choice you make will be a bit of a hack. That being said, consider these options:
A) In login.php, set $headerCss = '.error { color: '.$errorColor.'; } '
, then in header.inc.php, right before the </head>
tag, add:
if ($headerCss) {
print '<style type="text/css">';
print $headerCss;
print '</style>';
}
B) Another possible hack is to set $pageName = 'login'
, then have a switch that tests for the page name in header.inc.php, like:
if ($pageName == 'login') {
print '<style type="text/css">';
print ' .error { color: #900; }';
print '</style>';
}
.error{ color: #900; }
needs to be inside a <style>
tag inside <head>
, not at the very top of the document.
<?php
header('content-type:text/css', replace);
header("Expires: " . gmdate("D, d M Y H:i:s", (time()+900)) . " GMT");
$errorColor = '#900';
$css = array();
$css[] = '.error{ color: '.$errorColor.'; }';
?>
<?php include 'inc/header.inc.php';?>
<p class="error">Error MSG</p>
<?php include 'inc/footer.inc.php';?>
Then, inside inc/header.inc.php
, have something like this within your <head>
tag:
if (is_array($css)) {
echo '<style type="text/css">' . implode("\n", $css) . '</style>';
}
Updated to the following, inc/header.inc.php:
<?php
//Include a error reporting:
include '../../errorReport.inc.php';
// Set default timezone:
define('TZ', date_default_timezone_set('America/Los_Angeles') );
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>
<?php
if(defined('TITLE'))
{
print TITLE;
} else {
print 'Raise High the Roof Beam! A J.D. Salinger Fan Club';
}
?>
</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="./c/screen.css" media="screen,projection" />
<?php
if(is_array($css)) {
echo '<style type="text/css">';
foreach ($css as $constant)
{
//print"<p />$prop";
foreach($constant as $vars){
echo $vars;
}
}
echo '</style>';
}
?>
</head>
<body>
<div id="wrapper">
<div id="header">
<p class="description">A J.D. Salinger Fan Club</p>
<h1><a href="index.php">Raise High the Roof Beam!</a></h1>
<ul id="nav">
<li><a href="books.php">Books</a></li>
<li><a href="#">Stories</a></li>
<li><a href="#">Quotes</a></li>
<li><a href="login.php">Login</a></li>
<li><a href="register.php">Register</a></li>
</ul>
</div><!-- header -->
<div id="sidebar">
<h2>Favorite Quotes</h2>
<p class="news">I don't exactly know what I mean by that, but I mean it.<br />- <em>The Catcher in the Rye</em></p>
<p class="news">I privately say to you, old friend... please accept from me this unpretentious bouquet of early-blooming parentheses: (((()))).<br />- <em>Raise High the Roof Beam, Carpenters and Seymour: An Introduction</em></p>
</div><!-- sidebar -->
<div id="content">
<!-- BEGIN CHANGEABLE CONTENT. -->
CSS TEST:
<?php
$errorColor = "#900";
$fontSize = "5em";
$cssColors = array('.error{ color: '.$errorColor.';}');
$cssfontSize = array('#mainHead{font-size: ' . $fontSize.';}');
$css = array('colors' => $cssColors, 'fontSize' => $cssfontSize);
?>
<?php include 'inc/header.inc.php';?>
<p class="error">Error MSG</p>
<?php include 'inc/footer.inc.php';?>
精彩评论