SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: css and php

  1. #1
    SitePoint Member
    Join Date
    Jan 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    css and php

    Hi all.
    The website i am working on has numerous files that i keep in different folders for ease of maintenance, using php to calculate the location of links:

    <?php
    $BASEURL =ht.. ://".$_SERVER['HTTP_HOST']."/module/office/";
    $IMAGEURL =ht..://".$_SERVER['HTTP_HOST']."/module/office/"."style/img";
    ?>
    I want to create 2 css style.sheets, 1 for ie and 1 for Firefox but do not want to have to place the code for the css links in each file. Is it possible to have php to identify the browser used and calculate the style sheet needed, something similar to above using an if statement?
    Sorry but my English is not the best.
    Thank you
    A

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Sure, take a look at some the comments for get_browser().

    Although I'd heavily urge you not to use this feature, you should not be using server-side logic to address client side issues.

    Just use some CSS conditionals and be done with it.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Member
    Join Date
    Jan 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi SilverBulletUK
    Do i place the conditionals in the same php file in the (admin/config folder) as BASEURL, as i said i do not want to have to repeat the code for each file.
    Thank you

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    No PHP should be involved really, you should have a single style sheet which works on all browsers, then a separate style sheet which addresses each problem in all expected browsers.

    Then it's just a matter of adding some CSS conditionals in your markup.

    default.css
    ---> ie-fixes.css
    ---> moz-fixes.css
    ---> safari-fixes.css

    Or at least, that's how I would proceed.

    Either way, you will be addressing each style/browser variant no matter which route you take. So you may as well do it in an accepted manner and not obfuscate the solution.

    Maybe someone in the CSS forums would be better suited to advise you?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    Django Jedi neron-fx's Avatar
    Join Date
    Sep 2007
    Location
    Bristol/Bath, UK
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi SilverBulletUK,

    Why is it bad to use a server-side language to detect browser type?

    I know that HTTP_USER_AGENT can be spoofed but just wondered what other reasons you have not utilising a server side language such as PHP?

    Are there Javascript alternatives?

    Thanks in advance
    Neron-Fx
    Everytime a user opens Internet Explorer, a web developer dies...
    http://www.savethedevelopers.org/

  6. #6
    SitePoint Member
    Join Date
    Jan 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for putting me on the right track, I am going to do more research on the topic.
    A

  7. #7
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I'm not saying it's bad, but you're bypassing a native browser / CSS solution for this.

    I don't see why you would intentionally mix the presentation layer with server-side logic and hide away your fix in a non-standard way.

    For example... Possibly years down the line when you have left the employ of your client they wish to restyle the application and hire a designer to alter the CSS to suit. Why in the world would they look in the PHP source for this magical function of yours that is no longer relevant?

    This solution is a hack, there is a proper and compliant way to do it but you choose not to for sheer ease.

    Again, this is all just my opinion, and no doubt someone is about to shoot me down and offer their opinion!
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  8. #8
    Django Jedi neron-fx's Avatar
    Join Date
    Sep 2007
    Location
    Bristol/Bath, UK
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SilverBulletUK View Post
    I'm not saying it's bad, but you're bypassing a native browser / CSS solution for this.

    I don't see why you would intentionally mix the presentation layer with server-side logic and hide away your fix in a non-standard way.

    For example... Possibly years down the line when you have left the employ of your client they wish to restyle the application and hire a designer to alter the CSS to suit. Why in the world would they look in the PHP source for this magical function of yours that is no longer relevant?

    This solution is a hack, there is a proper and compliant way to do it but you choose not to for sheer ease.

    Again, this is all just my opinion, and no doubt someone is about to shoot me down and offer their opinion!
    Nope this makes perfect sense was just curious to your reasoning that is all, I wasn't having a go or anything!

    You are right I do it that way for sheer ease but will rethink this method now having read the above
    Neron-Fx
    Everytime a user opens Internet Explorer, a web developer dies...
    http://www.savethedevelopers.org/

  9. #9
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think is the best way to handle ie specific content.

    http://msdn.microsoft.com/en-us/library/ms537512.aspx

  10. #10
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by neron-fx View Post
    I wasn't having a go or anything!
    Of course not, and I hope you didn't think my post was retaliatory*.

    *Although I probably should have taken a breath or two!
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  11. #11
    Django Jedi neron-fx's Avatar
    Join Date
    Sep 2007
    Location
    Bristol/Bath, UK
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SilverBulletUK View Post
    Of course not, and I hope you didn't think my post was retaliatory*.
    HAHA! no not at all If anything it was because I re-read my post and felt it might have come across as a bit blunt or rude Just wanted to inform you that it wasn't meant that way at all
    Neron-Fx
    Everytime a user opens Internet Explorer, a web developer dies...
    http://www.savethedevelopers.org/


Bookmarks

Posting Permissions

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