• Welcome to The Cave of Dragonflies forums, where the smallest bugs live alongside the strongest dragons.

    Guests are not able to post messages or even read certain areas of the forums. Now, that's boring, don't you think? Registration, on the other hand, is simple, completely free of charge, and does not require you to give out any personal information at all. As soon as you register, you can take part in some of the happy fun things at the forums such as posting messages, voting in polls, sending private messages to people and being told that this is where we drink tea and eat cod.

    Of course I'm not forcing you to do anything if you don't want to, but seriously, what have you got to lose? Five seconds of your life?

Another Styleswitcher fail

Put this at the top of your code, it should print any errors that the parser encounters:

Code:
<?php 
ini_set('error_reporting', E_ALL);
?>

Or, just add the ini_set('error_reporting', E_ALL); to the PHP code block that you've already got. Make sure it's at the top, though.
 
PHP:
<?php

('error_reporting', E_ALL);

if(isset($_COOKIE['style']){
    $no = intval($_COOKIE['style']);
    $style['1'] = 'http://ditto.ifastnet.com/stylesheet.css';
    $style['2'] = 'http://ditto.ifastnet.com/stylesheet2.css';
    $style['3'] = 'http://ditto.ifastnet.com/stylesheet3.css';
    $style['4'] = 'http://ditto.ifastnet.com/stylesheet4.css';
    print "<link rel='stylesheet' href='" . $style[$no] . "' />";
}
else { 
    print "<link rel='stylesheet' media='all' type='text/css' href='/stylesheet.css' />";  
}

?>

Like so?
 
Which bracket?

Oh, duh. Nevermind that.

Ok, so when I corrected that, and added it to my pages, I opened up the file on my own system, and this is what I saw:

"; } else { print ""; } ?> and then the rest of my page, with no formating. Does this help?
 
Last edited:
Ok, so when I corrected that, and added it to my pages, I opened up the file on my own system, and this is what I saw:

"; } else { print ""; } ?> and then the rest of my page, with no formating. Does this help?

Sounds like a faulty editor or something.

Oh, never mind that, I was thinking you were looking at the actual file. In the browser, of course; it treats everything between the angled brackets as html. This includes <?php * />.
 
Well, I was e-mailing with Peter, and I got it fixed! Or at least the default style appears. When I click the links to some of the other styles, the page refreshes, but the default style shows up again.
 
Does that go on every page also? or just the place where the choice of style is made?
 
Wherever the links are to change styles. Example:
<a href="http://ditto.ifastnet.com/styleswitcher.php?style=1">Style 1</a>
<a href="http://ditto.ifastnet.com/styleswitcher.php?style=2">Style 2</a>
etc...

Upon clicking those, the style will be changed. :D
 
Okay, so I do that, and then when I click on the link on my actual page, it takes me to my 404.
 
Nonononono. XD

You have the links like this:
<a href="http://ditto.ifastnet.com/styleswitcher2.php?style=2">Link</a>
<a href="http://ditto.ifastnet.com/styleswitcher3.php?style=3">Link</a>

You only have to put the style number after the 'style=' part, not after 'styleswitcher'. :D
 
Gotcha!

And it's still not working. The normal style shows up fine on the home page, but on any other page, plain black and white. And when I click on a style, it takes me back to the home page, with the normal style

my about me file is an example of this

this is its code
PHP:
<?php
    $style[1] = 'http://ditto.ifastnet.com/stylesheet.css';
    $style[2] = 'http://ditto.ifastnet.com/stylesheet2.css';
    $style[3] = 'http://ditto.ifastnet.com/stylesheet3.css';
    $style[4] = 'http://ditto.ifastnet.com/stylesheet4.css';
if(!isset($_COOKIE['style']))
{
     $no = 1;
}

else
{
    $no = $_COOKIE['style'];
}
?>


This is what is in my styleswitcher file. I don't think it is a problem, because the index page works

PHP:
<?php

$style[1] = 'http://ditto.ifastnet.com/stylesheet.css';
$style[2] = 'http://ditto.ifastnet.com/stylesheet2.css';
$style[3] = 'http://ditto.ifastnet.com/stylesheet3.css';
$style[4] = 'http://ditto.ifastnet.com/stylesheet4.css';

$no = $_GET['style'];

if($style[$no]){
    $expiration = 60 * 60 * 24 * 365 * 100 + time();
    setcookie('style', $no, $expiration);
    
    header("Location: http://ditto.ifastnet.com/home.php");
}
elseif($no>count($style)){
    print "Invalid style! Please don't try to hack DD";
}
?>


and the link to change styles:

HTML:
<a href="http://ditto.ifastnet.com/styleswitcher.php?style=1">Normal Ditto Style</a><br>
<a href="http://ditto.ifastnet.com/styleswitcher.php?style=2">Shiny Ditto Style</a><br>
<a href="http://ditto.ifastnet.com/styleswitcher.php?style=3">Spring Style</a><br>
<a href="http://ditto.ifastnet.com/styleswitcher.php?style=4">Electric Style</a><br>
 
Last edited:
The reason the other pages aren't working right is you haven't changed the code to what I emailed you, lol. :] I changed it around a lot. =O


Maybe make sure the stylesheet HTML declaration is as follows:
PHP:
<link rel="stylesheet" href="<?php echo $style[$no]; ?>" type="text/css" />

My guess is that I messed up the piece at the top of the page on the first if() statement.

Although... try changing (in the styleswitcher.php file)
PHP:
if($style[$no]){
    $expiration = 60 * 60 * 24 * 365 * 100 + time();
    setcookie('style', $no, $expiration);
    
    header("Location: http://ditto.ifastnet.com/home.php");
}

TO

PHP:
if(file_exists($style[$no])){
    $expiration = 60 * 60 * 24 * 365 * 100 + time();
    setcookie('style', $no, $expiration);
    header("Location: http://ditto.ifastnet.com/home.php");
}

If that doesn't fix it, try changing the top from

PHP:
if(!isset($_COOKIE['style']))
{
     $no = 1;
}

TO

PHP:
if($_COOKIE['style'])
{
     $no = 1;
}

I'm sure I could come up with more if I looked harder. There's a list of all kinds of stuff to fix. It works on my server; probably there's a piece of code that I copied incorrectly from my editor. :]
 
So I did the second thing, the part about styleswitcher.php, and it didn't work. So I changed this:

PHP:
if(!isset($_COOKIE['style'])) 
{ 
     $no = 1; 
}

And then my page returned to it's original non-formatted self.

I didn't do anything with this:

PHP:
<link rel="stylesheet" href="<?php echo $style[$no]; ?>" type="text/css" />
 
This code:

PHP:
if($_COOKIE['style'])
{
     $no = 1;
}

Will completely negate the point of the styleswitcher. Translate the code to English:

If the a cookie named style has a value, $no = 1.
 
So I put the site on hiatus so that we can get this fixed without people seeing our failed attempts.

PHP:
<?php
    $style[1] = 'http://ditto.ifastnet.com/stylesheet.css';
    $style[2] = 'http://ditto.ifastnet.com/stylesheet2.css';
    $style[3] = 'http://ditto.ifastnet.com/stylesheet3.css';
    $style[4] = 'http://ditto.ifastnet.com/stylesheet4.css';
if($_COOKIE['style'])
{
     $no = 1;
}  

else
{
    $no = $_COOKIE['style'];
}
?>

Each page

PHP:
<center><b>Styleswitcher</b><br>
<a href="http://ditto.ifastnet.com/styleswitcher.php?style=1">Normal Ditto Style</a><br>
<a href="http://ditto.ifastnet.com/styleswitcher.php?style=2">Shiny Ditto Style</a><br>
<a href="http://ditto.ifastnet.com/styleswitcher.php?style=3">Spring Style</a><br>
<a href="http://ditto.ifastnet.com/styleswitcher.php?style=4">Electric Style</a><br>

Links

PHP:
<?php

$style[1] = 'http://ditto.ifastnet.com/stylesheet.css';
$style[2] = 'http://ditto.ifastnet.com/stylesheet2.css';
$style[3] = 'http://ditto.ifastnet.com/stylesheet3.css';
$style[4] = 'http://ditto.ifastnet.com/stylesheet4.css';

$no = $_GET['style'];

if(file_exists($style[$no])){
    $expiration = 60 * 60 * 24 * 365 * 100 + time();
    setcookie('style', $no, $expiration);
    header("Location: http://ditto.ifastnet.com/home.php");
}  

elseif($no>count($style)){
    print "Invalid style! Please don't try to hack DD";
}
?>

styleswitcher.php
 
Back
Top Bottom