SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Apr 2003
    Posts
    208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multiple CSS Files

    JUST come up with this concept now

    How would I be able to do it so; every time the website refreshes it loads up a new .css file.

    For instance, someone goes to "the site" and they'll see a blue layout because it's loaded up the blue.css file. But then the user refreshes and it loads up the pink layout because it loaded up the pink.css file etc etc.

    For say a maximum of 10 css files or however many css files are in the css/ directory.

    Anyone got any ideas, links to help, or help themselves?

    Regards,
    Chris

  2. #2
    The short answer is yes... Herbster's Avatar
    Join Date
    Oct 2001
    Location
    Bay City, Oregon
    Posts
    715
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ASSuming you don't want to keep track of the CSS file via cookie/session, you could set up a little code to randomly select which CSS file is written to the head of the page you are serving.

  3. #3
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    have a file called css.php, with this:

    PHP Code:
    $css = array();
    $css[1] = ".text{ font-family...... }";
    $css[2] = "more stuff";

    if (isset(
    $_COOKIE['css']) && $_COOKIE['css'] < count($css))
    {
    echo 
    $css[$_COOKIE['css']];
    $new $_COOKIE['css'] + 1;
    set_cookie("css"$newtime() + * 3600 24 365
    }
    else
    {
    echo 
    $css[1];
    setcookie("css""1"time() + 3600 24 365);

    Then call it by "css.php" (linking it, or just putting an include with PHP.)

    It'll go through them.

  4. #4
    SitePoint Guru
    Join Date
    Aug 2001
    Location
    Amsterdam
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how to do it with css files

    Funny I didn't think of this but now you say it it really sounds nice...
    lets see

    PHP Code:
    $cssfiles = array();
    $handle =opendir($directory); // open the directory
    while ($file readdir($handle)) 
    {
     if ((
    $file != ".") && ($file != "..") ) 
     {
      
    $cssfiles[$i] = $file;
      
    $i++;
     }
     
    // now all the css files are in 1 array
    closedir($handle);  // closedir
    reset($cssfiles);
     
    srand ((float)microtime()*1000000); // get random
    shuffle ($cssfiles); //lets shuffle the deck
    // now just use $cssfiles[0] cause it's different everytime 
     
    echo $cssfiles[0]; 
    the neigbours (free) WIFI makes it just a little more fun

  5. #5
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's different, but it's not ordered, so you could end up having the same ones more than once in a row if there are only 2 or 3.

    However adding:

    PHP Code:
    $cssfiles = array();
    $handle =opendir($directory); // open the directory
    while ($file readdir($handle)) 
    {
    if ((
    $file != "." ) && ($file != ".." ) ) 
    {
      
    $cssfiles[$i] = $file;
      
    $i++;

    Into my cookie code should work well.

    Regards,
    Someonewhois

    (P.S. Thanks whoever gave me 14 reputation marks for this post )

  6. #6
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    while ($file readdir($handle)) 
    should be

    PHP Code:
    while (false !== ($file readdir($handle))) 
    (check www.php.net/readdir for an explaination)
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  7. #7
    SitePoint Guru
    Join Date
    Aug 2001
    Location
    Amsterdam
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cyborg from dh
    PHP Code:
    while ($file readdir($handle)) 
    should be
    PHP Code:
    while (false !== ($file readdir($handle))) 
    (check www.php.net/readdir for an explaination)
    if you have PHP 4+

    otherwise it don't work!!!!
    the neigbours (free) WIFI makes it just a little more fun


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
  •