0

I need PHP to generate part of a path name for my background image, which is used in a CSS-file. I changed the file type to PHP and added a header, as suggested in another post on StackOverflow. However, I cannot get it to work. I believe that the PHP generates and error and terminates all other code after that, but I am not sure how to acquire the error message. My code is:

<?php
    header('Content-type: text/css');
?>

body {
    min-height: 100%;
    background: url("<?php echo asset_url(); ?>images/backgroundImage.jpg");
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center top;
}

The asset_url() function has been tested, and is working elsewhere, so that should not be the issue. An example of it working is here:

<link rel="stylesheet" type="text/css" href="<?php echo asset_url(); ?>css/basicStyle.php">

Am I missing something totally obvious here?

Update: I am pretty sure the CSS is loaded, as it worked before I changed it to PHP (I did not change anything else). An inspection of the site, once uploaded, shows the following in

<link rel="stylesheet" type="text/css" href="http://e-drift.dk/assets/css/basicStyle.php">

However none of the CSS in the file is applied correctly, not a thing.

2
  • What does the css look like if you load the page? Commented Nov 27, 2014 at 11:28
  • Added an update to my main post, if that is what you meant. Commented Nov 27, 2014 at 11:33

3 Answers 3

1

Are you sure you're including any required includes?

Your error message shows this;

Call to undefined function asset_url() in /var/www/web/web694777/e-drift.dk/assets/css/basicStyle.php on line 7

Sign up to request clarification or add additional context in comments.

3 Comments

I am not including anything currently, as the function is usually made available through the CodeIgniter framework. However, it appears this is not the case here apparently.
I am working on a way to fix this, however I am now struggling on finding a command which provides the base path (either "e-drift.dk" or "e-drift.dk/application") so I dont have to hardcode the location. Any ideas?
@Noceo $_SERVER['HTTP_HOST'] (URL) or realpath(__DIR__.'/../..') (filesystem)?
0

You need to include the source of the function asset_url() in basicStyle.php :

    include('file-with-function.php')

Comments

0

Why would you save a Css file as a .php document?

Otherwise for your css document:

<?php
    header("Content-type: text/css; charset=utf-8");
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.