Jump to content


Layout help


8 replies to this topic

#1 Bengo

    Young Padawan

  • Members
  • Pip
  • 80 posts
  • Interests:Art, Graphic Design, Web Design

Posted 06 July 2005 - 02:30 AM

Ok like, I want to make it so like, I can make the layout change, like the skin of it. Sort of like Spoono, but I also want to add like a cookie so the browser or whatever remembers what skin it's on. I honestly don't know how to do either of those, and it'd be great if you guys could give me some tips.

#2 greg

    Jedi In Training

  • Members
  • PipPip
  • 499 posts
  • Location:New York City
  • Interests:Fine art, web and graphic design, naval architecture, chess, and sports.

Posted 06 July 2005 - 03:04 AM

That can be done with PHP and several stylesheets. If you are even slightly familiar with PHP, the following code should make some sense to you. If not, then ask something and I'll try to explain:
<?php
//session has to be started before html output
session_start();

echo"<html>\n";
echo"<head>\n";

if(isset($_GET['style']))
    {
        //put the new style selected by the user into the session
        $_SESSION['style'] = $_GET['style'];
    }
elseif(!isset($_GET['style']) && !isset($_SESSION['style']))
    {
        //if no style has been selected, set a default
        $_SESSION['style'] = 1;
    }

if(isset($_SESSION['style']))
    {
        //pick the current style and include that stylesheet
      switch ($_SESSION['style']) {

       case "1": $inc = 'stylesheet1.css';
       break;
                             
       case "2": $inc = 'stylesheet2.css';
       break;
                             
       case "3": $inc = 'stylesheet3.css';
       break;
                             
       default: $inc = 'stylesheet1.css';
       break;
       }
     }
     
$css_file = "<link href=\"".$inc."\" rel=\"stylesheet\" type=\"text/css\">\n";
echo $css_file;


?>
</head>
<body>

<a href="index.php?style=1">Style 1</a><br>
<a href="index.php?style=2">Style 2</a><br>
<a href="index.php?style=3">Style 3</a><br>

</body>
</html>
Basically, that code let's you choose between 3 stylesheets (you can edit it, of course), and remembers what you chose for as long as you don't close the browser window (a session).

Edited by greg, 06 July 2005 - 03:05 AM.


#3 Bengo

    Young Padawan

  • Members
  • Pip
  • 80 posts
  • Interests:Art, Graphic Design, Web Design

Posted 06 July 2005 - 06:20 PM

Makes sense, I'm planning on making my next site with this type of stuff. :D But like, when it says before HTML output, does that mean I put the code before the <html> tag?

Edited by Bengo, 06 July 2005 - 06:29 PM.


#4 greg

    Jedi In Training

  • Members
  • PipPip
  • 499 posts
  • Location:New York City
  • Interests:Fine art, web and graphic design, naval architecture, chess, and sports.

Posted 06 July 2005 - 10:06 PM

Yes, the session has to be started before you start the HTML.

#5 Bengo

    Young Padawan

  • Members
  • Pip
  • 80 posts
  • Interests:Art, Graphic Design, Web Design

Posted 06 July 2005 - 11:54 PM

Ah ok, thank you. This includes the cookie info also?(Just making sure.)

#6 coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 07 July 2005 - 01:28 AM

no it doesnt include cookies. its using sessions, so once the user closes the browser with the chosen style, it goes back to default once he comes back on.

#7 Chaos King

    Senior Programmer

  • P2L Staff
  • PipPipPip
  • 676 posts
  • Gender:Male
  • Location:Florida

Posted 08 July 2005 - 11:05 AM

http://www.forums.pi...p?showtopic=981

Here, I made one because I wanted to haev multiple skins my site at one point.

You might be too lazy to look at the link so i will post it here...



----------------------------------------------



As you may of seen on http://www.spoono.com They have a skin changer! This is something similar and it has the same idea as theirs. Just that this has a refresh page that will bring you back to the last page page you were viewing instead of going back to the home page.

1) First off, create your index.php This will have a very few lines of code, and add this in there:

Quote

//COOKIE MONSTER
ini_set("session.cookie_lifetime", "315360000");
session_start();

//Settign the styles
switch($_SESSION["style"])
{
case "red":
  include("red.php");
  break;
/*
To add a new skin, simply add:
case "NAME OF SKIN":
  include("FILENAME TO SKIN");
  break;
*/
default:
  include("default.php");
  break;
}
?>

All your skins will be in different files. Your default skin will be set to default.php So you would set up that file the same you would with index.php. If you wanted a red skin. You could simply create the red skin on the file red.php with the images set to the red images and etc. Please also note:

Quote

/*
To add a new skin, simply add:
case "NAME OF SKIN":
  include("FILENAME TO SKIN");
  break;
*/

2) Now, create a style.php and insert this code:

Quote

//COOKIE MONSTER
ini_set("session.cookie_lifetime", "315360000");
session_start();
$_SESSION["style"] = $_GET["set"];
?>

Please Wait...
 

 

  layout scheme selected, please wait to be redirected...
 

 

( Click here if you are not redirected in 3 seconds )


Please notice the code $HTTP_REFERER which is the last page you visited. If you did not visit a page before the style page is loaded. You are stuck :ph34r:

To change a skin, you can simply set a hyperlink to

Quote

style.php?set=red
and it will redirect you to the index.php but this time, it is loading from the red theme.

Final Notes: Cookies must be enabled for this to work. Also, this is a lifetime cookie so it will take a LONG time to expire.

If you have any questions, comments, suggestions, please feel free to speak your mind.

Tutorial Copyright © 2005 Chaos King -- Pixel-Designz

#8 Jamie Huskisson

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 3,648 posts
  • Gender:Male
  • Location:Nottingham, UK

Posted 08 July 2005 - 11:11 AM

there are more effective ways to do this using javascript, and AJAX

also, including all style sheets in the code and marking them as alternative stylesheets help the switching, as the user already has the stylesheet and the switch is seemless, almost instant

#9 Chaos King

    Senior Programmer

  • P2L Staff
  • PipPipPip
  • 676 posts
  • Gender:Male
  • Location:Florida

Posted 08 July 2005 - 11:17 AM

hehe...
Unfortunatly, I have not even tried to learn those...

Please say how would you do it in Java/AJAX, I can always learn something new! :ph34r:





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users