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 4122746
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:31:17+00:00 2026-05-20T23:31:17+00:00

I have a bunch of CSS files that get loaded on every page (header,

  • 0

I have a bunch of CSS files that get loaded on every page (header, global, main page, footer, etc.).

I have written a simple PHP script that compiles them into a single string and then outputs that string.

<?php
    set_include_path('../');
    header('Content-Type: text/css');

    $q = $_GET['q'];

    $patterns = array(
                        '/.*[\.]{2,}.*/',
                        '/,\//',
                        '/^\//'
                    );

    $replacements = array(
                        '',
                        ',',
                        ''
                    );

    $q = preg_replace($patterns, $replacements, $q);

    $css = explode(",", $q);

    $output = '';

    foreach( $css as $link )
    {
        $output .= include($link);
    }

    print $output;
?>

it can be called (and the way I am calling it) like this:

<?php
$cssLinks = array(
                    "/global/global.css",
                    "/styles/local.css",
                    $tmpl->headerContent['css']['link'],
                    $tmpl->appContent['css']['link'],
                    "/styles/css3buttons.css"
             );
$css = implode(",", $cssLinks);
?>
<link rel="stylesheet" href="/components/CSS.php?q=<?= $css; ?>" type="text/css" />

Which results in a string like this:

<link rel="stylesheet" href="/components/CSS.php?q=/global/global.css,/styles/local.css,/styles/header.css,/styles/index.css,/styles/css3buttons.css" type="text/css" />

This is fine, and – more importantly – it works.

What is my question, then, you ask?

It’s a two-parter:

  1. What security vulnerabilities am I overlooking in the script?
    • I’ve removed any directory traversal possibilities, but what else?
    • I do need to be able to change what the links are, so I can’t hard-code them into this script. For example, $tmpl->appContent['css']['link'] is a dynamic stylesheet for each page, of which there will be many.
  2. How can I add line breaks between the included files?
    • I’ve added $output .= '\n\n'; in the foreach() loop, but it doesn’t work.
    • I’m still stuck with output like:

#footer, #push {
height: 3em;
padding-top: 1em;
}#header{

The CSS listed works but I would prefer to have the #header block two lines down, like:

#footer, #push {
height: 3em;
padding-top: 1em;
}

#header{

(I apologize about the strange code block, Markdown broke horrendously on those hashes, and I couldn’t figure out how to fix it).

Note, this lack of line breaks only happens at the junction between two different files. The code inside each CSS file is formated just as it should be.

  • 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-20T23:31:18+00:00Added an answer on May 20, 2026 at 11:31 pm

    You should prefer to pass only basenames to the CSS.php merge script:

    <link rel="stylesheet" href="CSS.php?q=global,local,header,index,css3buttons" type="text/css" >
    

    Then it becomes safer to implement in CSS.php with just:

    preg_match_all('#\w+#', $_GET["q"], $files);
    
    foreach ($files[0] as $fn) {
    
         foreach (array("global/$fn.css", "local/$fn.css") as $fn)
             if (file_exists($fn)) 
                $content .= file_get_contents($fn);
    
         $content .= "\n\n";
    
    }
    

    The only difference is that this script now has a little intelligence and knows where to look for the stylesheets. So you don’t lose the flexibility of having variable stylesheet parts glued together.

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

Sidebar

Related Questions

I have a bunch of files that I need to be able to transport
I have a bunch of perfmon files that have captured information over a period
I have a bunch (hundreds) of files that are supposed to have Unix line
I have a page that has a bunch of different iframes (A, B, C,
I have a bunch of CSS files with a bunch of classes. I know
I have a bunch of latitude/longitude pairs that map to known x/y coordinates on
I have a bunch of .NET frameworks installed on my machine. I know that
I have a bunch of PDF files and my Perl program needs to do
I have a bunch of reports that are printed out and mailed to clients.
when we use Expires header for text files like js, css, contents are cached

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.