Page 2 of 3

Posted: Wed Mar 02, 2005 10:01 am
by smpdawg
Take a look at this package. It may make template creation with PHP easier and faster for you.

http://www.php-tools.de/site.php?file=/ ... /intro.xml

Posted: Wed Mar 02, 2005 10:21 am
by horsleyaa
Personally I think this will not help.
All I need to know is how can I make it so users select different styles

Posted: Wed Mar 02, 2005 10:24 am
by smpdawg
Then would this be of more help to you? http://www.alistapart.com/articles/bodyswitchers/

Posted: Wed Mar 02, 2005 10:28 am
by horsleyaa
I am actually using my own version of one of these scripts to change the stylesheet.
What I want is to generate PHP pages that use values.
so the page would have the content and say the colour of a piece of text would be given the value $test1colour
The colour would be looked up and then the text would display in that colour. I want to have several "stylesheets" (they may not be stylesheets) that the user can pick from . The chosen one would be remembered and future pages would generate usin gthis stylesheet.
The links on the page would have to end in ?[name of stylesheet] automatically
I hope this is clearer

Posted: Wed Mar 02, 2005 10:37 am
by smpdawg
Gotcha.

What I did on another project was use one stylesheet and place keywords in the CSS. The keywords would be some unique pattern that isn't likely to appear in CSS like $FONTCOLOR$. That is not meant to be a variable but instead a pattern that can be located by a search. Then I would read the CSS and do a search and replace on those keywords based on the users preferences. I would then send that CSS with the web page.

The user preferences were stored in a database and when they logged in I would get their preferences and store them in the session.

You could also provide a dropdown that had some standard styles. If the user picks a style, you load those preferences into session variables and use them. That way a unregistered user can change styles.

This system let me change font size, color, logos, etc. purely based on their choices and there was only one stylesheet to edit.

edit - You could also do as you say and have a URL that includes http://www.domain.com/index.php?style=style1.css. Then use code like this to get the name.

Code: Select all

$stylesheet = (isset($_GETї'style'])) ? $_GETї'style'] : 'default.css';
Then do something like this to load that stylesheet.

Code: Select all

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

Posted: Wed Mar 02, 2005 10:39 am
by horsleyaa
I don't quite understand how to do this.
Please could you explain
Also I don't have access to a database which is a major problem.

Posted: Wed Mar 02, 2005 10:43 am
by smpdawg
Please read the previous post. I added an example that may be more like what you need.

Posted: Wed Mar 02, 2005 10:49 am
by smpdawg
<style>
<!--
a:link {
font-color: %LINKCOLOR%;
font-size: %LINKSIZE%;
}
etc..
-->
</style>
Then in PHP you would do a

Code: Select all

$CSSContents = file_get_contents($pathToCSS);
$CSSContents = str_replace('%LINKCOLOR%", '#0000ff', $CSSContents);
$CSSContents = str_replace('%LINKSIZE%", '12px', $CSSContents);

... more ...

echo $CSSContents;
And replacing the path, color, etc. as appropriate.

Posted: Wed Mar 02, 2005 11:11 am
by horsleyaa
I don't full understand how you could do this. could you explain in a bit more detail.
thanks

Posted: Wed Mar 02, 2005 11:12 am
by smpdawg
Which part do you have questions about?

Posted: Wed Mar 02, 2005 11:15 am
by horsleyaa
<style>
<!--
a:link {
font-color: %LINKCOLOR%;
font-size: %LINKSIZE%;
}
etc..
-->
</style>
Where would this go?
$CSSContents = file_get_contents($pathToCSS);
$CSSContents = str_replace('%LINKCOLOR%", '#0000ff', $CSSContents);
$CSSContents = str_replace('%LINKSIZE%", '12px', $CSSContents);

... more ...

echo $CSSContents;
How does this work?

Posted: Wed Mar 02, 2005 11:24 am
by smpdawg
The script would go in whatever page is generating the HTML inside of the HEAD tags.

So if you had something that did this.

Code: Select all

<HTML>
  <HEAD>
    <TITLE>My page</TITLE>
  </HEAD>
  <BODY>
    Your content here.
  </BODY>
</HTML>
You would do this.

Code: Select all

<HTML>
  <HEAD>
    <TITLE>My page</TITLE>
<?php
  $CSSContents = file_get_contents($pathToCSS);
  $CSSContents = str_replace('%LINKCOLOR%", '#0000ff', $CSSContents);
  $CSSContents = str_replace('%LINKSIZE%", '12px', $CSSContents);
  echo $CSSContents;
?>
  </HEAD>
  <BODY>
    Your content here.
  </BODY>
</HTML>
That would spit out a page that has the CSS inside of it and the tags would have been replaced to whatever value or variable that you would like.

And the CSS would be in some file that the script could see.

Posted: Wed Mar 02, 2005 11:33 am
by horsleyaa
<?php
$CSSContents = file_get_contents($pathToCSS);
$CSSContents = str_replace('%LINKCOLOR%", '#0000ff', $CSSContents);
$CSSContents = str_replace('%LINKSIZE%", '12px', $CSSContents);
echo $CSSContents;
?>
What does this mean?
How does it work?
thanks

Posted: Wed Mar 02, 2005 11:37 am
by smpdawg
You would use sessions. At the top of each page that generates HTML, you would call to a function that would call session_start(). Then you see if the session variable for font color is set, if not you could give a default. If the user selected a different 'style' you could replace the defaults.

e.g.

Code: Select all

function sessionHandling() &#123;
  session_start();
  $_SESSION&#1111;'linkcolor'] = (isset($_SESSION&#1111;'linkcolor'])) ? $_SESSION&#1111;'linkcolor'] : '#0000ff';  // The #0000ff is the default
  $_SESSION&#1111;'linkcolor'] = (isset($_SESSION&#1111;'linksize'])) ? $_SESSION&#1111;'linksize'] : '#0000ff';  // The 12ox is the default
 etc.
&#125;
The above code would use the session value if it exists or would assign it if it is missing. This way you know that you will always have some value in there.

Having used code similar to what is above, whenever you needed a value you would then access the $_SESSION array to get it like this.

Code: Select all

$_SESSION&#1111;'linkcolor']
Like this example.

Code: Select all

$CSSContents = str_replace('%LINKCOLOR%", $_SESSION&#1111;'linkcolor'], $CSSContents);

Posted: Wed Mar 02, 2005 11:43 am
by horsleyaa
I think I understand.
Could you give an example of a page that uses this (the code for the page)

how do the session work?