Thread: PHP and CSS

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Posts
    3
    Rep Power
    0

    PHP and CSS


    Hi..

    I was wondering how I can include different css files.

    For example, want a visitor to be able to click on a link that would load the same page, with a different css file. Sort of like picking skins.

    Can anybody help me? I'd be very grateful!

    Thank-you.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    Hi,

    For your links' href attribute, which is your php script, include a query sting like this:

    href="your_php_script.php?css=style_1"
    href="your_php_script.php?css=style_2"
    href="your_php_script.php?css=style_3"

    Then in your php script do this:
    Code:
    if ($css == style_1)
    {
       include('style_1.css');
    }
    else if ($css == style_2);
    {
      include('style_2.css');
    }
    else
    {
      include('style_3.css');
    }
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Posts
    3
    Rep Power
    0
    Thank you so much! One question - does the code have to go in a certain place, or can it go anywhere?

    Thanks again
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    Hi,

    That's an html question: where would you normally have the text in the css file? The include() function just replaces itself with the text contained in the file you are including as if you had typed it there yourself.

    How about inside the <head> tags and between some <style> tags?
    Last edited by 7stud; June 19th, 2001 at 01:23 AM.
  8. #5
  9. No Profile Picture
    Code Junky
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2001
    Location
    Central Missouri
    Posts
    358
    Rep Power
    0
    Though the other answers to this are also correct, another approach to this is through the use of JS.. most of the modern browsers can change css style sheets without reloading the document.

    You can see examples of this at:
    http://www.projectseven.com/

    They use such things as form buttons, to change the style of a page.


    Naturally the PHP approach can do this as well, only PHP will have to reload the page. Granted, you could couple the use of a cookie, so your visitor could actually return to your site, using the same style they selected previously.

    Pro's and Con's.. the first method I mention, does require JS being enabled.. not really a concern much these days..

    I dunno.. I like the PHP idea far better

IMN logo majestic logo threadwatch logo seochat tools logo