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
https://forums.phpfreaks.com/topic/89820-solved-link-css-using-php-variable/
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?

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.

 

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>
[...]

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.