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:
joey
Senior Member
****

Avatar
Epoc Faileur.

Posts: 734
Reputation: 26
33 / Other / Flag
Joined: Dec 2006
O.P. Tongue  php/css switcher...?
im [trying to] make a css switcher for my site using php, and i suck at php still XD

why wont it work?
this is in the head section -


code:
<?php
$myStyleColour = $_POST['styleColour'];

if($myStyleColour=="red"){
    print '<link rel="stylesheet" type="text/css" href="css/styles2.css" />';
    } else{
    /*if($myStyleColour=="normal")*/
    print '<link rel="stylesheet" type="text/css" href="css/styles.css" />';
    }
?>

and this is in the body -

code:
<input type="radio" name="styleColour" value="red" onselect="<?php
print "$myStyleColour"; ?>">Red<br>
<input type="radio" name="styleColour" value="normal" onselect="<?php
print "$myStyleColour"; ?>">normal<br>


any help would be appreciated, and no doubt its something stupid/obvious/is a syntaxical error :P

This post was edited on 02-08-2008 at 01:25 PM by joey.

Break my heart all you want, i'm on the NHS.
ever wondered what it's like to ejaculate through your ears...? ;o
02-08-2008 01:24 PM
Profile E-Mail PM Web Find Quote Report
ShawnZ
Veteran Member
*****

Avatar

Posts: 3146
Reputation: 43
32 / Male / Flag
Joined: Jan 2003
RE: php/css switcher...?
"$myStyleColour" isn't a javascript function...
Spoiler:
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
02-08-2008 01:27 PM
Profile PM Web Find Quote Report
joey
Senior Member
****

Avatar
Epoc Faileur.

Posts: 734
Reputation: 26
33 / Other / Flag
Joined: Dec 2006
O.P. RE: php/css switcher...?
and nither is the rest of the script. =p

im guessing i cant have a php thing in the onselect= ? but how else would i do it?

Break my heart all you want, i'm on the NHS.
ever wondered what it's like to ejaculate through your ears...? ;o
02-08-2008 01:30 PM
Profile E-Mail PM Web Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
RE: php/css switcher...?
You'll have to use Cookies or Sessions and then use that
code:
<?php
$myStyleColour = $_POST['styleColour'];

if($myStyleColour=="red"){
print '<link rel="stylesheet" type="text/css" href="css/styles2.css" />';
} else{
/*if($myStyleColour=="normal")*/
print '<link rel="stylesheet" type="text/css" href="css/styles.css" />';
}
?>

on the pages where you want to switch the styles, but you'll also need another script to actually do the switching and set the Cookie or session accordingly
[Image: 1-0.png]
             
02-08-2008 03:53 PM
Profile PM Web Find Quote Report
ShawnZ
Veteran Member
*****

Avatar

Posts: 3146
Reputation: 43
32 / Male / Flag
Joined: Jan 2003
RE: php/css switcher...?
quote:
Originally posted by icd*
and nither is the rest of the script. =p

im guessing i cant have a php thing in the onselect= ? but how else would i do it?

well even if you could do that, you're not setting it to anything there, just echoing it..
Spoiler:
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
02-09-2008 10:15 AM
Profile PM Web Find Quote Report
joey
Senior Member
****

Avatar
Epoc Faileur.

Posts: 734
Reputation: 26
33 / Other / Flag
Joined: Dec 2006
O.P. RE: php/css switcher...?
aah good point XD


* joey goes to learn some more php and will one day not suck at something.

Break my heart all you want, i'm on the NHS.
ever wondered what it's like to ejaculate through your ears...? ;o
02-09-2008 04:54 PM
Profile E-Mail PM Web Find Quote Report
ShawnZ
Veteran Member
*****

Avatar

Posts: 3146
Reputation: 43
32 / Male / Flag
Joined: Jan 2003
RE: php/css switcher...?
btw: check out ASP.NET. it allows you to do things like add events to HTML that will call back to the server and run .NET code.
Spoiler:
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
02-09-2008 07:49 PM
Profile PM Web Find Quote Report
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
joey
Senior Member
****

Avatar
Epoc Faileur.

Posts: 734
Reputation: 26
33 / Other / Flag
Joined: Dec 2006
O.P. RE: php/css switcher...?
haha! lol ty for that, looks hawt :P


not a complete waste of time, as im going to use it when i get round to working on my site again XD <3333

Break my heart all you want, i'm on the NHS.
ever wondered what it's like to ejaculate through your ears...? ;o
02-16-2008 08:37 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


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