• 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

Diz

Overdosing on placebos
You might not remember this, but I was epic fail at the Java Script styleswitcher, and now I'm working on a PHP one.

I followed the guide on this page.

Is there something missing?

In case that isn't enough, here's my code:

PHP:
<?php

$style['1'] = 'stylesheet.css';
$style['2'] = 'stylesheet2.css';
$style['3'] = 'stylesheet3.css';
$style['4'] = 'stylesheet4.css';

$no = intval($_REQUEST['style']);

if($style[$no]){
    $expiration = 60 * 60 * 24 * 365 * 100 + time();
    setcookie('style', $no, $expiration);
    $http = parse_url($_SERVER['HTTP_REFERER']);
    $gotourl = "ditto.ifastnet.com/home.php" . $http['path'];
    header("Location: $gotourl");
}else {
    print "Invalid style! Please don't try to hack DD";
}
?>
^In the file called styleswitcher.php

PHP:
<?php

if(isset($_COOKIE['style'])){
    $no = intval($_COOKIE['style']);
    $style['1'] = 'stylesheet.css';
    $style['2'] = 'stylesheet2.css';
    $style['3'] = 'stylesheet3.css';
    $style['4'] = 'stylesheet4.css';
    print "<link rel='stylesheet' href='" . $style[$no] . "' />";
}
else { 
    print "<link rel='stylesheet' href='DEFAULT.css' />"; 
}
?>
^On each page

PHP:
<a href="http://ditto.ifastnet.com/styleswitcher.php?style=1">Normal Ditto Style</a>
<a href="http://ditto.ifastnet.com/styleswitcher.php?style=2">Shiny Ditto Style</a>
<a href="http://ditto.ifastnet.com/styleswitcher.php?style=3">Spring Style</a>
<a href="http://ditto.ifastnet.com/styleswitcher.php?style=4">Electric Style</a>
^What I used to put a link to each style

Through all of this, I just get a default black and white layout, no styles at all.
 
Well, styleswitcher.php doesn't exist, so of course your style won't change. Your style just looks like that.

btw, your stylesheet seems to crash the w3 css validator, which is probably a bad thing.
 
Woah.

Thanks for the help, though.

EDIT: I checked, and my ftp client says that styleswitcher.php does exist
 
Last edited:
Do you actually have a DEFAULT.css? You need to set that to your default stylesheet.
 
Yeah, I realized that, and fixed it so that it is now stylesheet.css

I think I may have found the problem, but I don't know how to fix it. You see, I looked at the source of my pages, and the PHP I entered doesn't show up. However, when I open my FTP client, and look at the file that I have uploaded to the internet, it shows the the PHP.
 
Last edited:
...PHP doesn't show up when you view the source. That's the whole point; it's executed on the server. The user never receives the PHP.
 
Oh, that cool, but how is it going to fix my problem?

I was e-mailing with Nick, the person who wrote the guide I used, and he helped me with a bit. This is what I have so far:

PHP:
<?php

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'] = '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" />"; 
}
?>
^on each page

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 = intval($_REQUEST['style']);

if($style[$no]){
    $expiration = 60 * 60 * 24 * 365 * 100 + time();
    setcookie('style', $no, $expiration);
    $http = parse_url($_SERVER['HTTP_REFERER']);

     $gotourl = "http://ditto.ifastnet.com/home.php" . $http['path'];
    header("Location: $gotourl");
}else {
    print "Invalid style! Please don't try to hack DD";
}
?>

^Styleswitcher.php

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

^Right.txt
 
Last edited:
There's a syntax error in the first block of code. It seems the host is configured to not show fatal errors, which really sucks for development purposes.

PHP:
<?php

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'] = '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' />"; // change this line
}
?>
^ code on each page, with my change noted by a comment (the double quotes inside that quote should be single quotes)

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 = intval($_GET['style']); // $_REQUEST includes cookie values. If you use $_REQUEST here, if the user already has the cookie set they can't change it without deleting the cookie manually. Since you don't seem to access the script with $_POST let's just stick to $_GET

if($style[$no]){
    $expiration = 60 * 60 * 24 * 365 * 100 + time();
    setcookie('style', $no, $expiration);
    $http = parse_url($_SERVER['HTTP_REFERER']);

     $gotourl = "http://ditto.ifastnet.com/home.php" . $http['path'];
    header("Location: $gotourl");
}else {
    print "Invalid style! Please don't try to hack DD";
}
?>

^ styleswitcher.php

That being said, I'm not really sure why the cookie isn't being set. That styleswitcher code sets a cookie on my server (try it yourself), which to me tells me either some other code you haven't posted here is the problem, or some server configuration that is beyond your control. Let's see the rest of home.php and maybe I can find the problem
 
Code:
<html>

<head>

<title>Ditto's Docks</title>

<?php

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" />"; 
}
?>


<link 
href="http://i291.photobucket.com/albums/ll294/sam_gamgee_frodo/Sitepics/favicon.png" 
rel="shortcut icon" type="image/PNG" />

</head>

<body leftmargin="0" rightmargin="0" topmargin="10" bottommargin="10">

<div id="centerlayout">

<table cellspacing="0" cellpadding="0" border="0">
<tr><td valign="top" align="center" id="banner" colspan="3"></td></tr>
<tr>
<td valign="top" id="leftmenu">

<?php include "left.txt"; ?>

</td>
<td valign="top" id="content">
<div align="justify">



<table cellspadding="5" cellspacing="0" border="0">
<tr>
<td valign="top" id="content">

<center><b>.:. Home .:.</b></center><br><br>

<!-- Site Meter -->
<script type="text/javascript" src="http://s49.sitemeter.com/js/counter.js?site=s49ditto11">
</script>
<noscript>
<a href="http://s49.sitemeter.com/stats.asp?site=s49ditto11" target="_top">
<img src="http://s49.sitemeter.com/meter.asp?site=s49ditto11" alt="Site Meter" border="0"/></a>
</noscript>
<!-- Copyright (c)2006 Site Meter -->

<p>Welcome to Ditto's Docks 2.0, _Ditto_'s revamped first website. Undoubtedly there will be more that are similar to this.

<h3> Updates!</h3>

<?PHP
$number=1;
include("/home/vol1000/if_3356282/htdocs/cutenews/show_news.php");
?>
<br>

Note: If you don't understand something I am talking about here, visit the <A href="http://ditto.ifastnet.com/oldupdates.php">Old Updates</A> Page. If that doesn't clear things up, Contact me. For more information on that, visit <A href="http://ditto.ifastnet.com/contactme.php">this page</A>. 

<h3> All hail the Site poll!</h3><br>
<form method=post action="http://poll.pollcode.com/vri"><table border=0 width=150 bgcolor="EEEEEE" cellspacing=0 cellpadding=2><tr><td colspan=2><font face="Verdana" size=-1 color="00000"><b>Heart Gold or Soul Silver</b></font></td></tr><tr><td width=5><input type=radio name=answer value="1"></td><td><font face="Verdana" size=-1 color="00000">Heart Gold!</font></td></tr><tr><td width=5><input type=radio name=answer value="2"></td><td><font face="Verdana" size=-1 color="00000">Soul Silver</font></td></tr><tr><td width=5><input type=radio name=answer value="3"></td><td><font face="Verdana" size=-1 color="00000">Neither</font></td></tr><tr><td width=5><input type=radio name=answer value="4"></td><td><font face="Verdana" size=-1 color="00000">Huh?</font></td></tr><tr><td colspan=2><center><input type=submit value="Vote">  <input type=submit name=view value="View"></center></td></tr><tr><td bgcolor="white" colspan=2 align=right><font face="Verdana" size=-2 color="black">pollcode.com <a href=http://pollcode.com/><font color="navy">free polls</font></a></font></td></tr></table></form>

<p>

</td></tr></table>



</div>
</td>
<td valign="top" id="rightmenu">

<?php include "right.txt"; ?>


</td></tr>
<tr><td valign="top" id="disclaimer" colspan="3">
</td></tr>
</table>
</body>
</html>
 
You have to change the latter stylesheet link too:

PHP:
print "<link rel='stylesheet' media='all' type='text/css' href='/stylesheet.css' />";

You can't have quotation marks inside a string that's enclosed by quotation marks unless you escape the quotation marks. The alternative is to use apostrophes when the string is enclosed by quotation marks and quotation marks when the string is enclosed by apostrophes.
 
PHP:
<?php

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' />";  
}
?>

^Each page

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 = intval($_GET['style']);

if($style[$no]){
    $expiration = 60 * 60 * 24 * 365 * 100 + time();
    setcookie('style', $no, $expiration);
    $http = parse_url($_SERVER['HTTP_REFERER']);

     $gotourl = "http://ditto.ifastnet.com/home.php" . $http['path'];
    header("Location: $gotourl");
}else {
    print "Invalid style! Please don't try to hack DD";
}
?>

^Styleswitcher.php
 
Why don't you just do this in your head element?

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

I wrote a style switcher that was much more simple... the PHP code in each page would just go above the stylesheet script. For example:

PHP:
<head>
<?php
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 { 
    $no = 1;  
}
?>
<link rel="stylesheet" type="text/css" href="<?php echo $style['no']; ?>" />

:D
 
PHP:
<head>
<?php
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 { 
    $no = 1;  
}
?>
<link rel="stylesheet" type="text/css" href="<?php echo $style['no']; ?>" />

That gets this:

HTML:
<link rel='stylesheet' href='whatever' />
<link rel="stylesheet" type="text/css" href="" />

or, if PHP is paranoid, fatal error.

er
 
Oops, I forgot to take out the line... let me fix it.

PHP:
<head>
<?php
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';
}
else { 
    $no = 1;  
}
?>
<link rel="stylesheet" type="text/css" href="<?php echo $style['$no']; ?>" />
</head>
 
PHP:
<head>
<?php
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';
}
else { 
    $no = '1';  
}
?>
<link rel="stylesheet" type="text/css" href="<?php echo $style[$no]; ?>" />
</head>

Is that correct?
 
er....Thats great and all, but I already have changed my files so many times, if you could just look at my scripts, tell me whats wrong with them and very specifically tell me what to do to fix them? Please and thanks. I do know nothing at all about PHP
 
Except that it's hardly as simple as that. All the code you posted in this thread runs fine on my server.
 
Back
Top Bottom