Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7616503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:54:14+00:00 2026-05-31T02:54:14+00:00

My globalStyles.css has been stable for 3 weeks and is used everywhere in the

  • 0

My globalStyles.css has been stable for 3 weeks and is used everywhere in the project. After studying several SO posts and responses it seems some people like to put their global CSS stuff into a .php file to avoid the type of problem I’m having.

Here is the issue.

At the top of my project’s files I have a PHP block — here’s the top of my index.php:

  <?php
   include 'titleBar.php';

   require_once 'navBar.php';

   require_once 'theDatabase.php'; // functions for the UI and DB access

   require_once 'globals.php'; // variables and statics used throughout
  ?>

Deeper into each file – such as my index.php above — is this statement:

   <link rel="stylesheet" type="text/css" href="<?php echo $sitePath ?>globalStyles.css" />     

$sitePath comes from globals.php, looks like this:

   $sitePath = "http://" . $_SERVER['HTTP_HOST'] . "/Artifacks/";

(‘Artifacks’ is the project name. Real nice, I didn’t pick it.)

Then I use $sitePath like this all over the place, for example:

 <img src="<?php echo $sitePath?>images/Artifacks-icon.png"></img>

Does this work? Oh my goodness. Incredible — like fresh Gumbo and biscuits. And stable for weeks too.

Notice that I said above the link rel=”stylesheet” globalStyles.css comes after the require_once ‘globals.php’
inside my index.php file (and all the other files in the project for that matter — globalStyles.css is pulled in AFTER globals.php, in all files).

By the time the link rel pulls the globalStyles.css into my index.php — the $sitePath is ‘visible’ already since it came from globals.php which was included before globalStyles.css.

So inside my globalStyles.css I added this:

   background-image: url('<?php echo $sitePath; ?>images/egypt-Sphinx.jpg ) ;

The image does NOT appear.

So I thought ‘okay even though globalStyles.css is pulled into index.php AFTER
the require_once ‘globals.php’ — for whatever reason my $sitePath in globals.php is not ‘visible’ to the code inside globalStyles.css.

To prove that, I hard-coded inside globalStyles.css the full path to egypt-Sphinx.jpg and this image now appears fine.

So I added this to globalStyles.css:

But my Netbeans IDE tells me “invalid content.”

How can I reference $sitePath inside globalStyles.css?

I need this statement to work — I can’t hardcode paths anymore because we’re deploying to the staging server then to the production server – I need to make the following work or to have its desired effect implemented SOMEhow:

Inside my globalStyles.css I need this to somehow work:

  .grayDecorative
   {
      background-image: url('<?php echo $sitePath; ?>images/egypt-Sphinx.jpg ) ;
      /* other styles here.........*/
   }

I have tried it without the semicolon after $sitePath and still no image.

When I ‘echo’ the $sitePath it DOES have a trailing slash:

    http://localhost/Artifacks/
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:54:15+00:00Added an answer on May 31, 2026 at 2:54 am

    If you need to run php in your stylesheet, then this should help.

    You will have to alter the structure just a bit. Change globalstyles to a php file, and call it in your link line like so: <link rel="stylesheet" type="text/css" href="<?php echo $sitePath ?>globalStyles.php" /> line.

    Then, rename the css to globalStyles.php, but add the following to the very top:

    <?php
        header("Content-Type: text/css");
        header("Vary: Accept");
    ?>
    

    You can now add any php that you need to the stylesheet. For example:

    background-image: url('<?php echo $sitePath; ?>images/egypt-Sphinx.jpg );
    

    will work, because it will get parsed by the php handler before it is returned as a stylesheet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my project I have put all my css classes in the style sheets.
As an example I got a css class which applies to all labels within
My CSS styles stop working if I type any argument following my landing page
Is there any way to create global styles for all TextBoxes used in application?
The code we used is from the less file that's related to positioning. The
I know for standard html attributes there are CSS selectors: span[class=example] But I would
I've been trying to do this to no avail :( From what I've researched,
I use the following throughout the project and until now did not notice an
Looking at SharpDevelop source code I found this button declaration: <Button Style={x:Static core:GlobalStyles.ButtonStyle} Content={core:Localize
I am setting global styles in iOS 5 with UIAppearance . Here's an example:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.