Hi all,
I'm currently looking to make a simple php script for my site which changes the value of a variable with the press of a button. The script is aimed at changing the CSS stylesheet of my site with a different one the way I 'd like to do do this is by using an echo of a variable inside the stylesheet path in the head tag.
For example a variable named $style1 with a value of "main.css", and when the button is pressed the value of $style1 changes to "second.css" therefore changing the path to the css file to a different path and reloading the page with that style on.
Any ideas on how I could achieve this? Bare in mind I want to keep the script very simple.
Thanks for any help in advance,
Andy C
Button to change variable string value
Moderator: General Moderators
Your best bet would be to make that a form and submit the required information (say, second.css) through a $_POST variable. When loading the page, you simply set "$style1=$_POST['style']" or whatever you would've named the input field. You should probably still make security checks, like stripping any html tags in case they'd try to put malicious javascript, but meh.
whitelist the available stylesheets in an array, then a simple in_array() check..
Code: Select all
<?php
$sheets = array('style1', 'style2', 'etc');
if (in_array($_POST['sheet'], $sheets)) {
$stylesheet = $_POST['sheet'] . 'css';
} else {
$stylesheet = 'default.css';
}
?>