Jump to content

Template switcher?


TR World

Recommended Posts

Create a dropdown box with the template names and when selected update a database field for that user with the template name and link to css file.

 

Have a file which fetch the user or session preferences

require(preferences.php);

 

which runs a query to get the stylesheet location for that user or session and assign it to a session variable $stylesheet

 

In your pages do something like

<link rel="stylesheet" type="text/css" href="<?php echo $stylesheet; ?>" />

Link to comment
https://forums.phpfreaks.com/topic/196847-template-switcher/#findComment-1033387
Share on other sites

Start with your code, dont worry about the drop down box yet especially if your really new to php.

 

To complete your idea you wil need to use: 1 or more IF Statements and implement sessions.

 

Sessions:

 

For every page that you want to store "User-Specific" data, (without them needing to log in), you use Sessions, and you must put "session_start();" at the top of your pages that use sessions.

 

Once you do that you can save session variables between page clicks, unique to each user. For example:

 

page1.php

<?php
session_start();

$_SESSION['test'] = "abc";

echo("<a href='page2.php'>See what happens:");

?>

 

page2.php

<?php
session_start();

echo("Previous Number: ".$_SESSION['test']");

?>

========

 

Then the IF Statement:

if.php

<?php

if($_SESSION['template'] == "template_1"){
  echo("<stylesheet src="1..." />");
}else{
  echo("<stylesheet src="2..." />");
}

?>

======

 

Now you can combine these to create a session enabled variable stylesheet template, hehe.

 

If you want a drop-down box you need to create a php form script, these are very simple and can be added easily like so:

 

form.php

<form method="post" action="process.php">
<SELECT name="stylesheet">
<OPTION value="1">Some Style Name</OPTION>
<OPTION value="2">Some Style Name 2</OPTION>
<OPTION value="3">Some Style Name 3</OPTION>
</form>

 

process.php

<?php

// Check for the form submittion:
if(isset($_POST['stylesheet'])){
  $_SESSION['stylesheet'] = $_POST['stylesheet'];
}
?>

 

then, on each page where the stylesheet would be:

 

<?php
echo("<stylesheet src='path/to/styles/$_SESSION['stylesheet'].css'");
?>

 

Good Luck.

-CB-

Link to comment
https://forums.phpfreaks.com/topic/196847-template-switcher/#findComment-1033494
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.