CSS Style switching using PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gretsch
    New Member
    • Sep 2007
    • 31

    #1

    CSS Style switching using PHP

    After lots of problems trying to allow the visitor to switch styles using Javascript - but encountering browser incompatabiliti es!!
    I decided to use PHP and found a simple way of doing it here:
    http://www.geek-notes.com/css/23/cascading-style-sheet-switcher/

    But it's not quite working ... could someone help me with the syntax please

    It consists of 4 parts:
    1 -
    Code:
    <link href=”/path/<?php echo $style ?>.css” rel=”stylesheet” type=”text/css” />
    2 - [ note - I changed on the 1st line their "<php" to "<?php" ]
    [PHP]<php
    if(isset($_COOK IE[’style’])){
    $style=$_COOKIE[’style’];
    } else {
    $style=’default ’; //the name of default style file
    }
    ?>[/PHP]
    3 - [ A file called 'switch.php' consiting of the following: ]
    [PHP]<?php setcookie(”styl e”, $_GET[”style”], time()+31536000 );
    header(”Locatio n:”.$HTTP_SERVE R_VARS[”HTTP_REFERER”]);
    ?>[/PHP]
    4 - [ and in the body: ]
    [HTML]<a href=”/switch.php?styl e=default”>View page with Default style!</a>
    <a href=”/switch.php?styl e=alternate”>Vi ew page with Alternate style!</a>[/HTML]
    I named my 2 css files 'default.css' and 'alternate.css' and they are in the root directory.

    When I click to select the default I get a 404 looking for:
    http://test.domain.com/”switch.php?sty le=pp_style_tes t”
    ie with quotes included around the argument ! (Nb - I've removed above the client's real domain name to protect the innocent ;-)

    I also notice (when viewing the source) that the link has been passed by php as:
    <link href=”’default’ .css” rel=”stylesheet ” type=”text/css” />
    ie with single quotes around the default.

    Can someone tell me where I/Geek_notes have gone wrong - thanks
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Whoever wrote that has used some strange single quotes which aren't recognised as a string by php.. they look like back-quote type things.

    Change them to single quotes.. i.e every quote in you if/else statement.

    Comment

    • Gretsch
      New Member
      • Sep 2007
      • 31

      #3
      Originally posted by markusn00b
      Whoever wrote that has used some strange single quotes which aren't recognised as a string by php.. they look like back-quote type things.

      Change them to single quotes.. i.e every quote in you if/else statement.
      Thanks, there's no way I would have known/spotted this.

      I changed them in the if/else statement and got the following error msg:
      Parse error: parse error, unexpected ':' in /web/sites/user/7/243/65335/public/test/switch.php on line 2


      In case it makes any difference, I'm testing in a "Test" domain, rather than the "www" domain the full domain is "test.domain.co m".

      Any ideas what's wrong?
      Last edited by Gretsch; Jan 4 '08, 08:58 PM. Reason: Correction as further info found later

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        [php]
        <?php setcookie("styl e", $_GET["style"], time()+31536000 );
        header("Locatio n: ".$HTTP_SERVER_ VARS['HTTP_REFERER']);
        ?>
        [/php]
        Changed those strange looking quotes to ones that work!

        I'd check all code you use from that site.. those quotes will just drive you mad!

        :)

        Comment

        • Gretsch
          New Member
          • Sep 2007
          • 31

          #5
          Originally posted by markusn00b
          [php]
          <?php setcookie("styl e", $_GET["style"], time()+31536000 );
          header("Locatio n: ".$HTTP_SERVER_ VARS['HTTP_REFERER']);
          ?>
          [/php]
          Changed those strange looking quotes to ones that work!

          I'd check all code you use from that site.. those quotes will just drive you mad!

          :)
          Brilliant - it now works fine.
          Thanks v much for your time & help.

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by Gretsch
            Brilliant - it now works fine.
            Thanks v much for your time & help.
            No problamooo

            Post back anytime.

            Comment

            Working...