Jump to content

[SOLVED] Link CSS using PHP variable


Grant Holmes

Recommended Posts

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.