Grant Holmes Posted February 6, 2008 Share Posted February 6, 2008 I hope my subject line is close! At the top of my php page in the <HEAD> is this: <LINK REL="stylesheet" TYPE="text/css" HREF="CSS/SEC.css"> I have another page on my site where I store a bunch of variables: <?php include_once("security/Mysecurity.php"); ?> There I store: $MYcss = "../CSS/SEC.css"; How can I put that in the page so it recognizes the CSS? I've tried about 10 things and nothing works. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 6, 2008 Share Posted February 6, 2008 You want to use the $css var by including it to another page? page_1.php <?php $css_link = "test.css"; define("CSS_LINK",$css_link,true); ?> page 2 <?php include("page_1.php"); define("CSS_LINK",true); include(CSS_LINK); ?> Quote Link to comment Share on other sites More sharing options...
Grant Holmes Posted February 7, 2008 Author Share Posted February 7, 2008 phpSensei, I tried that, and several variations and can't get it to work. I think we're on the same page, but let me restate, just in case. ON the variables page, I want to define where the CSS is for this "section". On the page(s) of this section, I want to call that one variable for where the CSS is. This is not a critical issue, but am trying to learn as I do this too. That help? Quote Link to comment Share on other sites More sharing options...
aschk Posted February 7, 2008 Share Posted February 7, 2008 What is written out in your html page at the present time? Because by the looks of it your path is wrong... Your $css variable is "../CSS/SEC.css" yet when you wrote out your static html page example (above) it was "CSS/SEC.css", see the difference? Quote Link to comment Share on other sites More sharing options...
ricerocket Posted February 7, 2008 Share Posted February 7, 2008 I don't think there is any way to link a css to page using variables through another page unless the mysecuirty file had the css not in a variable then you could just use require 'mysecuirty.file'; and it should work. I think. I'm just a beginner at php, so srry if I'm not making sense. Quote Link to comment Share on other sites More sharing options...
aschk Posted February 7, 2008 Share Posted February 7, 2008 Wait a sec are you trying to "include" the css file? Quote Link to comment Share on other sites More sharing options...
ricerocket Posted February 7, 2008 Share Posted February 7, 2008 I understand what he means he means that he wants to include the "MYsecurity.php" file and included within that files is the css and he wants the css to be available to the first file through the mysecurity.php file. From what I understand. Quote Link to comment Share on other sites More sharing options...
JacobYaYa Posted February 7, 2008 Share Posted February 7, 2008 Not sure if this is what you are looking for but maybe vars.php <?php $myCss = '../css/sec.css'; //Make sure path is correct ?> section.php <?php include 'vars.php'; ?> <html> <head> <link rel="stylesheet" href="<?php echo $myCss; ?>" /> </head> [...] Quote Link to comment Share on other sites More sharing options...
Grant Holmes Posted February 7, 2008 Author Share Posted February 7, 2008 JacobYaYa, You nailed it. That works great. ricerocket, you were correct. This one is solved. Coooooool stuff. Thanks gang! Quote Link to comment Share on other sites More sharing options...
haku Posted February 7, 2008 Share Posted February 7, 2008 It may work, but I suspect your code is probably messed up. Do you have a <head> in both documents? I'm guessing you do, otherwise you wouldn't have a CSS link in the included document. If the included document has a <head> in it, and you are including it above the <head> in your other document, your code is going to be messed up. Its going to slow down browsers when they are trying to load it. Quote Link to comment Share on other sites More sharing options...
Grant Holmes Posted February 7, 2008 Author Share Posted February 7, 2008 I'm not sure I follow you, but the one file where the variables are stored, it is ONLY php and has no html or <HEAD> section Quote Link to comment Share on other sites More sharing options...
haku Posted February 7, 2008 Share Posted February 7, 2008 I see. Going back and looking at your code, I think you are ok. Sorry if I threw you off a little, just wanted to confirm for you. 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.