What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » php/css switcher...?

php/css switcher...?
Author: Message:
Fruit
New Member
*


Posts: 1
Joined: Feb 2008
RE: php/css switcher...?
EDIT: This board has ruined the indentation, so now my code looks uglier then it did in the first place :P. Just though I would add this in so some idiot does come along like "d000d use indentation FFS" which usually happens =/...well OK it doesn't but it could :O

EDIT AGAIN: Probably a good idea to say that there are easier ways to do this using JavaScript...:P..again jsut before somebody else comes along and says it.

code:
<?php

/****************************
SCRIPT: Colour Changer
AUTHOR: M.Mouse
IMPORTANT: It is important this script is located at the to of your page, there must be nothing before the <?php, not so much as an alphanumeric letter, or pubic hair.
DEVELOPMENT: took 15 minutes of MY time and about 5 mins debugging, wow what a waste of my time....but hey im bored, and nice so there.
LAST UPDATED: 19:33 10 February 2008

HOW TO USE: You can either just place it directly into your html files, inline, paying attention to the IMPORTANT note above. Or you can use the PHP include function, however this will still need to be located at the very top of your html files (which will need to be changed to .php anyway) > example below.
****************************/



//FUNCTION DEFS// 

//I suppose the ONE function in here isn't really needed you could jsut add it to the script, but yeah


//function - reads colour and outputs relevent css line --ooo i do love my whitespace
function OutputColour($colour) //requires a colour string
{
    //rest explains it's self really
    switch($colour)
    {
       
       
        case "b":
            return("BLUE CSS");
                break;
   
        case "r":
            return("RED CSS");
                break;
               
               
        case "g":
            return("GREEN CSS");
                break;
       
       
        case "d":
            return("WHAT EVER THE DEFAULT IS");
                break;
               
        case "WHAT EVER HERE":
            return("AND HERE - DUPE THIS BLOCK AS MANY TIMES AS YOU WISH");
                break;
       
       
        default: //this will only be reached if you haven't added another colour to this list correctly, or somebody has tried to tamper with their cookie (after we gave them it for free ;(...bastards
       
            setcookie("site_colour", "", mktime(12,0,0,1, 1, 1980)); //removed cookie by setting it to expire in the past
            header("location: ?"); //redirect to index
                break;
    }
   
}



//MAIN//


//some checks to prevent warnings from the php parser
if( isset($_GET["action"] ))
{
    $action = $_GET["action"]; //this data will not present a security risk so we don;t need to check it really, i guess you could check the length but thats up too you
}
else
{
    $action = NULL; //again just makes sure we don;t piss the parser off
}


//this will recieve the query string from the url
switch($action)
{
    case "colour": //if the query is change colour
   
        if( !isset($_POST['colour'])) // check if  a colour has been recieved
        {
            $colour = "d";//if not set colour to d, d = default
        }
        else
        {
            $colour = $_POST['colour']; //else if the POST data has been sent then use that
        }
       
        setcookie("site_colour", $colour); //set a cookie containing the selected colour
        header("location: ?"); //redirect user to index
            break;
           
    case "rmcookie": //removes the cookie, just so you can have one of those little "remove cookies set by this site blah blah.....thingys if you so wish
        setcookie("site_colour", "", mktime(12,0,0,1, 1, 1980)); //set the cookie to expire in the past..how naughty of us =P
        header("location: ?"); //again redirect back to index
            break;
           
    default: //this is the default action - if no query string is recieve then it will jsut act as normal and output your CSS
        if( !isset($_COOKIE['site_colour']) ) //if there is no cookie set
        {
            $colour = "d"; //set the colour to default
        }
        else
        {
            $colour = $_COOKIE['site_colour']; //else use the value stored int he cookie
        }
       
        echo( OutputColour($colour) ); //call the outputColour function and pass the colour along - output return
            break;
           
}


//END - it suppose it isn;t exacly what you wanted, i think the fact that i has to be at te top, and that it reidrects to the index might annoy you (Which i definetly didn't mean to do *cough* *cough*) but if gives you a basic idea of what to do, give me a shout if your stuck with summuit.
?>
<form action="?action=colour" method="post">
   
    <select name="colour">
        <option value="r">Red Theme</option>
        <option value="b">Blue Theme</option>
        <option value="g">Green Theme</option>
    </select>
   
    <input type="submit" value="change">
   
</form>

<br/>
<a href="?action=rmcookie">Remove Cookie</a>





PHP INCLUDE FUNCTION EXAMPLE:
you edit the last section of HTML out of the above code and place it in it's own file.

code:
<?php //<< again improtant this is first
include("test_css.php");
?>
<!--wow html malformed ftw? =P-->


<form action="?action=colour" method="post">
   
    <select name="colour">
        <option value="r">Red Theme</option>
        <option value="b">Blue Theme</option>
        <option value="g">Green Theme</option>
    </select>
   
    <input type="submit" value="change">
   
</form>

<br/>
<a href="?action=rmcookie">Remove Cookie</a>


SO yeah again a bit of a waste of time, but total it took like 25mins, it's a Sunday ngiht and i have nothing better to do (except for homework :/)

This post was edited on 02-10-2008 at 07:51 PM by Fruit.
02-10-2008 07:47 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
php/css switcher...? - by joey on 02-08-2008 at 01:24 PM
RE: php/css switcher...? - by ShawnZ on 02-08-2008 at 01:27 PM
RE: php/css switcher...? - by joey on 02-08-2008 at 01:30 PM
RE: php/css switcher...? - by Ezra on 02-08-2008 at 03:53 PM
RE: php/css switcher...? - by ShawnZ on 02-09-2008 at 10:15 AM
RE: php/css switcher...? - by joey on 02-09-2008 at 04:54 PM
RE: php/css switcher...? - by ShawnZ on 02-09-2008 at 07:49 PM
RE: php/css switcher...? - by Fruit on 02-10-2008 at 07:47 PM
RE: php/css switcher...? - by joey on 02-16-2008 at 08:37 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On