Jump to content

Novice Help With CSS Style Switcher


martcol

Recommended Posts

I am very new to this.

 

I have been using A List Apart for the code for a style swithcher on this page.

 

It doesn't work and I have been through it again and again and can't seem to spot any errors.  There isn't much code.  In the Head I have this:

 

<link href="stylemain.css" rel="stylesheet" type="text/css" media="all"/>
	<link rel="stylesheet" type="text/css" media="screen" title="User Defined Style" href="<?php echo (!$sitestyle)?'stylemain':$sitestyle ?>.css" />	
<link rel="alternate stylesheet" type="text/css" media="screen" title="Fire Engine Red" href="./style1.css" />
<link rel="alternate stylesheet" type="text/css" media="screen"  title="Grape" href="./style2.css" />
<link rel="alternate stylesheet" type="text/css" media="screen"  title="Scary" href="./style3.css" />		

 

Then a switcher.php file with this in it:

 

<?php
setcookie ('sitestyle', $set, time()+31536000,
'/', 'www.imagesandwords.org.uk', '0');
header("Location: $HTTP_REFERER");
?>

 

And in the body there's this:

 

<ul>
	<li id="red"><a href="switcher.php?set=style1">1</a></li>
	<li id="green"><a href="switcher.php?set=style2">2</a></li>
	<li id="blue"><a href="switcher.php?set=style3">3</a></li>
</ul>

 

I would like to learn PHP and this is my first exercise in it. I know a bit of HTML & CSS but programming to me means planning what to watch on the telly!

 

Even a pointer as to how to find out why it doesn't work for me would be great.

 

Thanks

 

Martin

Link to comment
Share on other sites

make sure the page is set as .php or that you have your server set to parse .html pages as php etc. When I view source on your page, I can see the php code. That means it is not being processed.

 

That should be the problem

Link to comment
Share on other sites

Thank you for your help.  I've tried changing the file extension to .php but it still doesn't work.  I have raked through the code symbol by symbol but, still no luck.

 

I take your point revras and realise that this isn't really about learning to code but I figured that it might be a way of learning to implement code.  I am reading two books on PHP but they are both way over my head.  I keep reading them though and have a nother one on order.  My trouble is I don't even understand basic programming.  I don't understand all that stuff about integers, arrays, strings etc.  I also hope that not knowing how to code won't prevent me from using some PHP.  My next step for instance, is a captcha.

 

Thanks

 

Martin

Link to comment
Share on other sites

I think that ALA has more recent versions of styleswitchers on their site.

 

The code you used assumes that register_globals is ON (which it was, several years back as the default in php).  The code you're using is hopefully running on a server with a less ancient version of php.  The solution to your problem should be to modify switcher.php to this:

 

<?php
$set = $_GET['set'];
setcookie ('sitestyle', $set, time()+31536000, '/', 'www.imagesandwords.org.uk', '0');
header("Location: $HTTP_REFERER");
?>

Link to comment
Share on other sites

Sorry about this.  I tried your suggestion AndyB and it's the same.  I can select the different styles using firefox >view>page style but the links (style switcher switches) don't do anything.

 

I'll Put my code here again but I wonder if there is some other set up thing that I should be doing.  What about the file permision in C Panel? At the moment I think the switcher.php is 644.

 

switcher.php: (and I've tried it with AndyB's suggestion).

 

<?php
setcookie ('sitestyle', $set, time()+31536000, 
'/', 'imagesandwords.org.uk', '0');
header("Location: $HTTP_REFERER");
?>

 

in my < head> (with two other style sheets listed but omitted here to save space):

 

<link rel="stylesheet" type="text/css" media="screen" title="User Defined Style" href="<?php echo (!$sitestyle)?'stylemain':$sitestyle ?>.css" />

<link rel="alternate stylesheet" type="text/css" media="screen" title="Red" href="red.css" />

 

In the < body>

 

<ul>
	<li id="Red"><a href="switcher.php?set=red">1</a></li>
	<li id="Green"><a href="switcher.php?set=green">2</a></li>
	<li id="Blue"><a href="switcher.php?set=blue">3</a></li>
</ul>

 

Regards

 

Martin

Link to comment
Share on other sites

I thought that I should mention that I put this little bit of php into my < body> <p><? print(Date("m/j/y")); ?></p>

to see if it works - and it does because it prints the date to the page.

 

Not sure if it makes a difference, but it made me feel better!

 

Martin

Link to comment
Share on other sites

I got it working but I am not sure why.

 

I changed my code to this - adding a return in front of the < ?php tag

 

<link rel="stylesheet" type="text/css" media="screen" title="User Defined Style" href="
<?php echo (!$sitestyle)?'stylemain':$sitestyle ?>
.css" />

 

And then taking out the return in the switcher.php file which I think, was before the '/'

 

<?php
setcookie ('sitestyle', $set, time()+31536000, '/', 'imagesandwords.org.uk', '0');
header("Location: $HTTP_REFERER");
?>

 

Thanks for your help

 

Martin

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.