Change style sheets depending on url

Discussion in 'PHP' started by dannywwww, Oct 23, 2008.

  1. #1
    Hey, i am working on a new project, and has the same concept of myspace (but very different features etc)

    So i am wanting to change the style sheet whilst on a profile page e.g.

    www.example.com - stylesheet 1
    www.example.com/?mod=signup - stylehsheet 1
    www.example.ccom/?mod=auth - stylesheet 1
    --
    www.example.com/danny - style sheet 2 (new style)
    (using mod rewrite from www.example.com/?viewprofile=danny)

    I tried using if/else but failed, does anyone have any advice on how to do it?


    Regards,
    Danny. :)
     
    dannywwww, Oct 23, 2008 IP
  2. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #2
    If should work. Show some code. How are you getting the url, are you using a function to extract the relevant pieces etc.
     
    shallowink, Oct 23, 2008 IP
  3. sastro

    sastro Well-Known Member

    Messages:
    214
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #3
    Save the stylesheet file name on session or cookie
     
    sastro, Oct 23, 2008 IP
  4. dannywwww

    dannywwww Well-Known Member

    Messages:
    804
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    110
    #4
    So i have finally got the basics to work...

    <?php 
    $pageurl .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    $profile = htmlentities($_GET['viewprofile']);
    if($pageurl == "www.example.com/?viewprofile=$profile"){
        echo "Profile CSS";
    }else{
        echo "Main CSS";
    }
    ?>
    PHP:
    Now is it even possible to work around the mod-rewrite rule.

    since it works as...
    www.example.com/?viewprofile=danny

    but not

    www.example.com/danny

    Any advice on how to do this?

    Thanks,
    Danny.
     
    dannywwww, Oct 23, 2008 IP
  5. salahsoftware

    salahsoftware Peon

    Messages:
    63
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    you may also name the page in a variable like $page_name="home.php" and check with if condition.
     
    salahsoftware, Oct 23, 2008 IP
  6. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #6
    if($pageurl == "www.example.com/$profile"){
    echo "Profile CSS";
    }

    could do it as an OR with the IF statement, elseif is an option too.
     
    shallowink, Oct 23, 2008 IP
  7. dannywwww

    dannywwww Well-Known Member

    Messages:
    804
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    110
    #7

    Thanks, finally got it to work :)

    <?php 
    $profile = htmlentities($_GET['viewprofile']);
    
    if(!$profile){
    	echo "<link href=\"$domain/templates/default/styles.css\" type=\"text/css\" rel=\"stylesheet\" />";
    }else{
    	echo "Main CSS";
    }
    ?>
    PHP:
     
    dannywwww, Oct 23, 2008 IP