Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Regular Coder
    Join Date
    Apr 2013
    Posts
    125
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question writing CSS using PHP?

    Hi,

    I am trying to write CSS using PHP by going through this tutorial:

    http://net.tutsplus.com/tutorials/ph...nder-the-hood/

    when I add this part:

    Code:
    AddHandler application/x-httpd-php .css
    to my .htaccess file on my local server, all styles then break.

    here is my dbstyle.css
    PHP Code:
    <?php header("Content-type: text/css; charset: UTF-8"); ?> 

    #headcontainer { background-color: #<?php echo $headcontainerbg?> }
    and I have imported it into my page too


    Please help

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    You need to use the header() function to output the css file mime type as css. If you don't the browser will assume its a text file.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #3
    Regular Coder
    Join Date
    Apr 2013
    Posts
    125
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I did use header() function,

    this is my CSS:
    PHP Code:
    <?php
    header
    ("Content-type=text/css; charset=UTF-8");

    $qry1="SELECT headcontainerbg FROM settings WHERE SiteID = '1'";
    $cur1=mysql_query($qry1);
    while(
    $j=mysql_fetch_row($cur1))
    {
    $headcontainerbg=$j[0];
    }

       
    ?> 

    #headcontainer { background-color: #<?php echo $headcontainerbg?> }

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Try dropping the charset part (including the ;). If that doesn't work then you may still have something somewhere else outputting another content type which is overriding it.

    You need to call the file manually and examine the headers. Also note that you may have trouble even using .css files with php inside if you're using Windows / IIS. Apache supports it with ease but IIS can be a lot of trouble.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #5
    Regular Coder
    Join Date
    Apr 2013
    Posts
    125
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I have done what you said:

    here is my CSS page:
    PHP Code:
    <?php header('Content-type=text/css');   ?> 

    #headcontainer { background-color: #<?php echo $headcontainerbg?> }
    here is my .htaccess (in the CSS folder)
    Code:
    AddType application/x-httpd-php .html .htm .css
    AddHandler application/x-httpd-php .html .htm .css
    AddHandler application/x-httpd-php5 .css
    I am using MAMP locally, still nothing

  • #6
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    So what is in the reply headers from the server? - I told you to look at them in my last reply.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #7
    Regular Coder
    Join Date
    Apr 2013
    Posts
    125
    Thanks
    3
    Thanked 0 Times in 0 Posts
    info php tells me:

    HTTP Headers Information
    HTTP Request Headers
    HTTP Request GET /dhs/info.php HTTP/1.1
    Host localhost:8888
    User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:21.0) Gecko/20100101 Firefox/21.0
    Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language en-US,en;q=0.5
    Accept-Encoding gzip, deflate
    Cookie SQLiteManager_currentLangue=2; PHPSESSID=08e1961bd940d11450a3294a5d36fc02
    Connection keep-alive
    HTTP Response Headers
    X-Powered-By PHP/5.3.6
    Keep-Alive timeout=5, max=100
    Connection Keep-Alive
    Transfer-Encoding chunked
    Content-Type text/html

  • #8
    Regular Coder
    Join Date
    Apr 2013
    Posts
    125
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Please help

  • #9
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,959
    Thanks
    2
    Thanked 304 Times in 296 Posts
    If you 'read between the lines' in that tutorial, every .css file that is affected by that .htaccess setting (your css folder) must have the php header() for the content type added to it.

    That tutorial suggests that your php produced .css files all be put into their own folder, where that .htaccess is at and regular .css files would then be somewhere else so that they are not affected by the .htaccess setting.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #10
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,133
    Thanks
    12
    Thanked 332 Times in 328 Posts
    the correct input for the content-type header is:
    PHP Code:
    header("Content-Type: text/css"); 
    in general, the structure is {header-type}:{header-value} as outlined in the respective RFCs (for HTTP Headers that would be mainly RFC 2616).
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • Users who have thanked Dormilich for this post:

    tangoforce (05-21-2013)

  • #11
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Jarv,

    I really do not know how to help you further - you always ignore my advice:

    Quote Originally Posted by jarv81178 View Post
    HTTP Request GET /dhs/info.php HTTP/1.1
    Why have you done this? I explicitly told you to call your CSS file and look at the headers for THAT http request. Instead you have called a file called info.php? Why? Jarv why do you ignore everything I tell you?

    Why did you not call your css file? Why did you not look at the css file headers?

    Quote Originally Posted by jarv81178 View Post
    Content-Type text/html
    This is what you need to look for in the headers from your css file. Not that you will bother as you always ignore my advice.

    Jarv, this is the final time I will give you a clear instruction: Go to your css file on your server:

    http://www.your-site.com/your-css-file.css

    Using a firefox plugin or IE plugin, check your http reply headers from the server.

    DO NOT use your info.php again for your css file, it is useless and only provides SERVER information.

    Edit: Also change your = to a : as Dorm has shown you.
    Last edited by tangoforce; 05-21-2013 at 10:01 AM.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #12
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    3 seconds on google found this (google is something you need to use a LOT more jarv):
    http://web-sniffer.net/

    Type in the URL to your css file and submit the form. It will show you the request and reply headers. You need to look at the content type of the REPLY headers.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #13
    Regular Coder
    Join Date
    Apr 2013
    Posts
    125
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hi Tangoforce,

    Sorry I didn't know what you meant by "look at the headers for THAT http request"

    I am testing locally so I cannot use web-sniffer.net

    When I point my browser to my CSS file it prompts me to open or save the file

  • #14
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    So get a plugin for your browser then which will let you examine the headers. I have already told you that above.

    Use google and search for a plugin. Seriously Jarv I admire you for persevering with PHP programming but you really must refine your debugging skills. Google is your friend yet you don't seem to understand how to search?

    If you use firefox then search for livehttp headers or httpfox.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #15
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,133
    Thanks
    12
    Thanked 332 Times in 328 Posts
    Quote Originally Posted by tangoforce View Post
    If you use firefox then search for livehttp headers or httpfox.
    Even the FireBug AddOn (Network tab) lets you examine Request/Response headers.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •