steelmanronald06 Posted September 23, 2006 Share Posted September 23, 2006 How would I do something like this in CSS with PHP? It doesn't work, but surely you can understand what I want:[code]#topnav { background:url($path/includes/teal.gif) repeat-x; padding-top:5px; color:#fff;}[/code] Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted September 23, 2006 Share Posted September 23, 2006 ok try[code]#topnav { background:url(<?php$path?>/includes/teal.gif) repeat-x; padding-top:5px; color:#fff;}[/code] Quote Link to comment Share on other sites More sharing options...
steelmanronald06 Posted September 23, 2006 Author Share Posted September 23, 2006 sorry, no dice Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted September 23, 2006 Share Posted September 23, 2006 have u defined the $path???try this i know wat went wrong there[code]<?phpEcho("#topnav { background:url($path/includes/teal.gif) repeat-x; padding-top:5px; color:#fff;}");?>[/code] Quote Link to comment Share on other sites More sharing options...
tomfmason Posted September 23, 2006 Share Posted September 23, 2006 ^ Yea that would work as well but I already had this type so here you go...[code]#topnav { background:url(<?php echo $path; ?>/includes/teal.gif) repeat-x; padding-top:5px; color:#fff;}[/code]Hope that works for you.Tom Quote Link to comment Share on other sites More sharing options...
steelmanronald06 Posted September 23, 2006 Author Share Posted September 23, 2006 neither works :( Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted September 23, 2006 Share Posted September 23, 2006 then your not defining the varible $path Quote Link to comment Share on other sites More sharing options...
tomfmason Posted September 23, 2006 Share Posted September 23, 2006 I agree. Also, are you renameing the css file to php? Quote Link to comment Share on other sites More sharing options...
tomfmason Posted September 23, 2006 Share Posted September 23, 2006 No steelman is correct. It does not work that way...You have to define the path not set a variable. So somewhere you have to do this.[code=php:0]define(path, 'http://www.yoursite.com', true);[/code]now you can do this in the css file. Once again you have to change the extentsion to php[code]#topnav { background:url(<?php path ?>/includes/teal.gif) repeat-x; padding-top:5px; color:#fff;}[/code]I tested this and it works fine..Sorry that i said that you were wrong before testing it my self.Tom Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted September 23, 2006 Share Posted September 23, 2006 You could use sessions.index.php:[code]<?phpsession_start();$_SESSION['path'] = "/home/you/public_html/something";echo <<<EOF<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"><head><title>Test site</title><link rel="stylesheet" type="text/css" href="stylesheet.php /></head><body><!-- some html here --></body></html>EOF;?>[/code]stylesheet.php:[code]<?phpsession_start();header("Content-type: text/css");echo <<<EOF#topnav { background:url({$_SESSION['path']}/includes/teal.gif) repeat-x; padding-top:5px; color:#fff;}EOF;?>[/code] Quote Link to comment Share on other sites More sharing options...
steelmanronald06 Posted September 23, 2006 Author Share Posted September 23, 2006 okay. I had $path = .; so that the file looked like ./includes/teal.gif but I guess I need to do:define(path, '.', true); Quote Link to comment Share on other sites More sharing options...
tomfmason Posted September 23, 2006 Share Posted September 23, 2006 yea that is what I did and it works fine. Once again I am sorry for telling you that you were doing something wrong before testing it my self..Good luck,Tom Quote Link to comment Share on other sites More sharing options...
steelmanronald06 Posted September 24, 2006 Author Share Posted September 24, 2006 Okay, just gave this a test and it doesn't work :(index.php[code]<?php$path = ".";define(root, '.', true);include($path.'/includes/overall_header.inc');echo '<h1>Blah</h1>';include($path.'/includes/overall_footer.inc');?>[/code]style1.css[code]#topnav { background:url(<?php root ?>/includes/teal.gif) repeat-x; padding-top:5px; color:#fff;}[/code]I know I have all the paths defined correctly :( Quote Link to comment Share on other sites More sharing options...
tomfmason Posted September 25, 2006 Share Posted September 25, 2006 I don't know what to tell you. It worked fine for me. The only difference was that I defined the entire url. May be you should try that instead of just ( . )Good Luck,Tom Quote Link to comment Share on other sites More sharing options...
yonta Posted September 25, 2006 Share Posted September 25, 2006 I think your file style1.css should be renamed to style1.php (so it can execute the php code). Quote Link to comment Share on other sites More sharing options...
trq Posted September 25, 2006 Share Posted September 25, 2006 For starters the first argument [i]define[/i] excepts is a string, not a constant.[code=php:0]define("root",".");[/code]However... constant or not, this has nothing to do with your problem. This...[code]#topnav { background:url(<?php echo $path; ?>/includes/teal.gif) repeat-x; padding-top:5px; color:#fff;}[/code]is perfectly legitimate code if your css file has the .php extension. You may also need to define the mime type however. Place this at the top.[code=php:0]<?php header("Content-type: text/css"); ?>[/code] Quote Link to comment Share on other sites More sharing options...
steelmanronald06 Posted September 28, 2006 Author Share Posted September 28, 2006 okay, now I can't even get they stylesheet to call. Here is what I have:index.php[code]<?phpob_start();define(root, '.', true);$path = ".";//require the headersrequire_once('includes/headers.php');// require the database connectionrequire_once('includes/db.php');//Require functions.phprequire_once('includes/functions.php');// require the top layoutrequire_once('includes/top.php');[/code]top.php[code]<!DOCTYPE htmlPUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html lang="en"><head><!--BEGIN META--><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><meta name="Keywords" content="free linux tutorials, free apache tutorials, free php and mysql tutorials, live forums, free classes, free forums, programming help, php help, mysql help, apache help, free php help, php tutorials" /><meta name="Description" content="LAMPGeekz offers free news, tutorials, classes, and live forums in Linux, Apache, MySQL, PHP, and more! Get all of your programming help here!" /><!-- Begin Stylesheets --><?phpecho "<link rel='stylesheet' type='text/css' href=$path.'/includes/style1.php' /><link rel='stylesheet' type='text/css' href=$path.'/includes/style1.php' media='print' />";?>[/code]I renamed the stylesheets as style1.php and style2.php just as said.style1.php[code]/* CSS Document */body { font-family:Verdana, arial, times, helvetica, arial, sans-serif; margin:0; padding:0; font-size:78%;}a { text-decoration:none;}a:hover { text-decoration:underline;} code { font-family:Verdana, arial, times, helvetica, arial, sans-serif; font-size:76%;}dt { font-weight:bold;}pre { font-family:Verdana, arial, times, helvetica, arial, sans-serif; font-size:76%;}/************************ HEADER TEXT ************/#title { font-size:1.9em; font-family:Georgia, verdana, arial, helvetica, arial, sans-serif; padding-left:100px; font-weight:normal; margin-top:10px;;}/********************** NAVIGATION IN TOP-RIGHT CORNER *****/#cornernav { float:right; margin-top:5px; margin-right:5px;}#cornernav a { color:#686868; padding-right:20px;}/*************************** INLINE NAVIGATION WRAPPER *****/#navwrap { position:relative; padding-top:1px; padding-bottom:1px; border-top:3px solid #888; border-bottom:2px solid #888;}/***************************** INLINE NAVIGATION *********/#topnav { background:url(<?php root ?>/includes/teal.gif) repeat-x; padding-top:5px; color:#fff;}#topnav ul{ height:2.4em; line-height:2.4em; list-style: none; padding:0; margin:0;}#topnav li{ float: left;}#topnav li a{ line-height:2.4em; float:left; width:80px; display: block; color: #fff; text-align: center;}/**************************** INPUT BUTTONS ********/input.side, input.blue { width:100px; background-color:#77abb8; font-weight: bold; font-size:1em; margin-top:2px; color: #f0f0f0; margin-left:20px; height:23px;}input.blue { width:40px;}/**************************** SEARCH BAR ************/#search { position:absolute; top:5px; right:10px;} /****************************** SIDE NAVIGATION ****/#sidenav { float:left; margin-left:20px; margin-top:20px; width:200px; border-left:1px solid #c4c4c4; border-right:1px solid #c4c4c4; border-bottom:1px solid #c4c4c4;}#sidenav ul { list-style-type:circle;}#sidenav p.search { padding-left:1em; padding-bottom:10px;}#sidenav li { padding-top:0.6em !important; padding-top:0.4em;}#sidenav li a { color:#000;}#sidenav li a:hover { color:#2279af;}#sidenav h2 { font-size:100%; background:url(<?php root ?>/includes/teal.gif); color:#fff; height:1.8em; line-height:1.8em; padding-left:15px; margin-top:0;}/************************* MAIN CONTENT AREA ******* */#content { width:66%; float:left; margin-left:30px; margin-top:20px;}#content p { text-indent:20px;}#content a { color:#77aab8; text-decoration:none;}#content a:hover { text-decoration:underline;}#content img { float:left;}#content h1 { height:1.8em; line-height:1.8em; background:url(<?php root ?>/includes/grey.gif) repeat-x; border-top:1px solid #c4c4c4; margin-top:0; font-size:1.2em; color:#000; padding-left:5px;}/* ************************* FOOTER ***************** */#footer { clear:both; height:3em; border-top:1px solid #77abb8; text-align:center; color:#000; margin-top:2em; font-size:.8em;}#footer a { color:#000;}#ads { clear:both; height:3em; text-align:center;}[/code]style2.php[code]/* CSS Document */#sidenav, #topnav, #navwrap, #cornernav { display:none}#content h1 { background:#fff; border:0;} #content { width:100%;} #title { text-align:center;}#footer { border:0;} [/code]sorry it took so long to test. you posted your solutions and I haven't had time to do any coding on top of homework, work, and college activities. Quote Link to comment Share on other sites More sharing options...
steelmanronald06 Posted September 29, 2006 Author Share Posted September 29, 2006 *bump* Quote Link to comment Share on other sites More sharing options...
steelmanronald06 Posted October 2, 2006 Author Share Posted October 2, 2006 anyone able to help me with this one? Quote Link to comment Share on other sites More sharing options...
steelmanronald06 Posted October 3, 2006 Author Share Posted October 3, 2006 *BUMP!* Quote Link to comment Share on other sites More sharing options...
tomfmason Posted October 3, 2006 Share Posted October 3, 2006 Have you tried placeing a [code=php:0]header("Content-type: text/css");[/code]at the top of your css files?Here is an article that is somewhat related to your question. This is manly geared towards using php to avoid [url=http://www.stylegala.com/articles/no_more_css_hacks.htm]Css Hacks[/url]. If I were you I would read some of the comments.Good Luck,Tom Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted October 3, 2006 Share Posted October 3, 2006 background:url(<?php root ?>/includes/teal.gif) repeat-x;Short hand isn't safeuse <?php echo $root; ?>if that's what you are trying to do, and he's right you didn't try passing the header.It looks like your using some form of templating system. It iwll probably work once you pass it that header, it won't work if you don't, that tells the browser that it's a css file. It also has to be valid css, that hte php outputs. Quote Link to comment Share on other sites More sharing options...
tomfmason Posted October 3, 2006 Share Posted October 3, 2006 You could also place this in a htaccess to tell apache to parse css like php.[code]AddHandler application/x-httpd-php .css[/code]This is what I do..Tom Quote Link to comment Share on other sites More sharing options...
steelmanronald06 Posted October 4, 2006 Author Share Posted October 4, 2006 it is saved as .php, it has the header thing in it, and i even did businessmans suggestion. nothing nothing, and nothing. :( Quote Link to comment Share on other sites More sharing options...
neylitalo Posted October 4, 2006 Share Posted October 4, 2006 The PHP engine never sees that CSS file. The client's browser finds the file when it sees the <link> tag, and it never goes through the PHP engine - the client requests that file from apache, which delivers it just as it sees it.\tomfmason's suggestion will almost work, but he's got a couple Apache directives and their syntax mixed up. The directives you would want to set would be either:[code]AddHandler x-httpd-php .css[/code]or[code]AddType application/x-httpd-php .css[/code]And you'll want to make sure that you set the variable $path in the CSS file - but since I think you're going for portability here, that doesn't make sense at all. It would make more sense to just hard-code it into the CSS file, since that's effectively what would be going on anyway. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.