Jump to content

Recommended Posts

Hi, recently, before I moved hosts, my styleswitcher was working fine. Right now, I was trying to set the style, but it wouldn't work. Here's an example:

 

 

http://www.sprites-unlimited.com/

 

 

The code in styleswitch.php is as follow:

 

<?setcookie ('sitestyle', $set, time()+31536000, '/', 'sprites-unlimited.com', '0');
header("Location: $HTTP_REFERER");
?>

 

Yes, it's that A List Apart article, if you recognize this. It won't work. It returns a blank page for no reason. I made sure my style sheets existed.

Link to comment
https://forums.phpfreaks.com/topic/59859-styleswitcher-problem/
Share on other sites

<? setcookie('sitestyle', $_POST['set'], time()+31536000);
header("Location: ".$_SERVER['HTTP_REFERER']);
?>

 

I had a look through my cookies and it's not set at all.

 

If the REFERER doesn't work you could always make the target for the form on the index page to

<?php

echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
?>

 

and then make the location = $_GET['oldURL']

Link to comment
https://forums.phpfreaks.com/topic/59859-styleswitcher-problem/#findComment-297674
Share on other sites

Referer works, though the cookie is not set. I can't seem to find my problem, it came out of the nowhere. Here's my stylesheet declaration:

 

 


<link rel="stylesheet" type="text/css" title="default" href="<?php echo 
(!$sitestyle)?'default':$sitestyle ?>.css" />


<link rel="alternate stylesheet" type="text/css" title="blue" href="blue.css">
<link rel="alternate stylesheet" type="text/css" title="orange" href="orange.css">

Link to comment
https://forums.phpfreaks.com/topic/59859-styleswitcher-problem/#findComment-297778
Share on other sites

styleswitch.php

<? setcookie('sitestyle', $_POST['set'], time()+31536000);
header("Location: ".$_SERVER['HTTP_REFERER']);
?>

 

 

index.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Sprites Unlimited // The Ultimate Resource</title>

<link href="http://sprites-unlimited.com/favicon.ico" rel="shortcuticon" type="image/icon">

<base href="sprites-unlimited.com/">


<link rel="stylesheet" type="text/css" title="default" href="<?php echo 
(!$sitestyle)?'default':$sitestyle ?>.css" />


<link rel="alternate stylesheet" type="text/css" title="blue" href="blue.css">
<link rel="alternate stylesheet" type="text/css" title="orange" href="orange.css">

<meta name="keywords" content="Sprites,SPRITES,sprites,sprites unlimited,megaman,pokemon,kirby,sprites unlimited,unlimited sprites,game sprites">
<meta name="description" content="Rather Mediocre collection of sprites for NES,SNES,N64,GBA,GB,Genesis, & more!">
<meta name="robots" content="index,follow">
<meta name="revisit-after" content="1">


</head>
<body>
<div id="header">

</div>

<div id="container">
<div id="content">
<div align="center">


<form action="styleswitch.php" method="post">
<select name="set">
<option value="default" selected>56K White</option>
<option value="orange">Classic Orange</option>
<option value="blue">Icicle Blue</option>
</select>
<input type="submit" value="Change Style">
</form>

<a href="http://www.dino-productions.net/"><img src="http://www.drunkduck.com/Megaman_EXE/gfx/DP.PNG" border="0" alt="Dino Productions"></a><BR>
<a href="http://www.drunkduck.com/Megaman_EXE/index.php"><img src="http://www.drunkduck.com/Megaman_EXE/gfx/EXE.PNG" border="0" alt="Megaman EXE"></a><BR>
<a href="http://www.sprites-unlimited.com/forum/index.php"><img src="http://www.drunkduck.com/Megaman_EXE/gfx/DPNET.PNG" border="0" alt="DP NET"></a><BR>
</div>
<hr>

<?php
//Main Variables
$misc = "misc.php";
$news = "cutenews/show_news.php";
$error = "404.php";
$ext = ".php";
//Include Misc stuff
include $misc;
//Include News, and use ?id=
if(!isset($_GET['id'])){
include $news;
}
elseif($_GET['id'] == "main") {
include $misc;
include $news;
}
elseif(isset($_GET['id']) && file_exists($_GET['id'].$ext)){
include $_GET['id'].$ext;
}
//404 Error Page
else{
include $error;
}

?>
</div>

<div align="center">
<a href="http://www.drunkduck.com/Megaman_EXE/index.php" target="_blank"><img src="http://img79.imageshack.us/img79/7898/syxbh4.png" border="0" alt="By me"></a>
</div>

<div id="leftmenu">
<ul>

<h1>Site</h1>
<ul>
<li><a href="/">Home</a></li>
<li><a href="?id=Tutorial">Ripping tutorial</a></li>
<li><a href="?id=staff">Staff</a></li>
<li><a href="?id=Contact">Submit/Contact</a></li>
<li><a href="?id=LinkUs">Link to Us</a></li>
<li><a href="?id=Links">Links</a></li>
<li><a href="?id=disclamer">Disclaimer</a></li>
</ul>
<h1>Games</h1>
<ul>

<li><a href="?id=Classic">Classic</a></li>
<li><a href="?id=NES">NES</a></li>
<li><a href="?id=SNES">SNES</a></li>
<li><a href="?id=GBC">Game Boy</a></li>
<li><a href="?id=GBA">GBA</a></li>
<li><a href="?id=Genisis">Genesis</a></li>
<li><a href="?id=DS">Nintendo DS</a></li>

<li><a href="?id=PC">PC/Internet</a></li>
<li><a href="?id=Custom">Custom</a></li>
<li><a href="?id=map">Game Maps</a></li>
</ul>
<h1>Affiliates</h1>
<ul>
<li><a href="http://www.sprites-inc.co.uk/" target="_blank"><img src="http://img144.imageshack.us/img144/9117/inchs4.png" border="0" alt="Sprites Inc."></a></li>
<li><a href="http://www.parahosting.net/" target="_blank"><img src="http://www.parahosting.net/images/button2.png" border="0" alt="Parasyte Hosting"></a></li>
<li><a href="http://www.pokeuniverse.co.nr" target="_blank"><img src="http://i15.photobucket.com/albums/a396/ACTIONGAMER/affybuttons/affylink9cs.png" border="0" alt="Pokeuniverse"></a></li>
<li><a href="http://www.bmestudioz.com/" target="_blank"><img src="http://i15.photobucket.com/albums/a396/ACTIONGAMER/affybuttons/bmestudioz.gif" border="0" alt="BME Studioz"></a></li>
<li><a href="http://www.vglan.com/" target="_blank"><img src="images/VGlan.PNG" border="0" alt="Video Game LAN"></a></li>
</ul>
<h1>Topsites</h1>
<ul>
<a href="http://www.parahosting.net/topsites/index.php?a=in&u=spaceyoshix"><img src="http://www.parahosting.net/topsites/button.php?u=spaceyoshix" alt="Parasyte Top10 Hostees" border="0" /></a>
<a href="http://www.bmestudioz.com/topsites/" target="_blank"><img src="http://www.bmestudioz.com/topsites/button.php?u=spaceyoshix" alt="BME StudioZ Topsites" border="0" /></a>
</ul>
<h1>Links</h1>
<ul>
<li><a href='http://tsgk.captainn.net/' target="_blank"><img src="http://tsgk.captainn.net/img/banner_88x31_tsgk-03.png" border=0 alt='The ShyGuy Kingdom'></a></li>
</ul>

<h1>Statistics</h1>
<ul>
<li><script type="text/javascript" language="javascript">
var sc_project=1751497; 
var sc_invisible=0; 
var sc_partition=16; 
var sc_security="7f833bfb"; 
var sc_text=2; 
</script>
Hits:<script type="text/javascript" language="javascript" src="http://www.statcounter.com/counter/counter.js"></script><noscript><a href="http://www.statcounter.com/" target="_blank"><img  src="http://c17.statcounter.com/counter.php?sc_project=1751497&java=0&security=7f833bfb&invisible=0" alt="site stats" border="0"></a> </noscript></li>
<li>Online:<script type="text/javascript" src="http://fastonlineusers.com/on3.php?d=www.sprites-unlimited.awardspace.com"></script></li>
</ul>

</ul>

</div>
</div>
</div>
</body>
</html>

 

 

I'm using PHP 5.2.3

Link to comment
https://forums.phpfreaks.com/topic/59859-styleswitcher-problem/#findComment-298119
Share on other sites

I think the problem is that the COOKIE is never read, which means the switcher isn't going to switch regardless of how many times the cookie value is changed.

 

I suspect it_just_broke when you/your host upgraded php to a version that has register_globals OFF

 

Here's an example php switcher that READS the cookie value - http://gr0w.com/articles/code/css_stylesheet_switcher_using_php/index.php

 

Link to comment
https://forums.phpfreaks.com/topic/59859-styleswitcher-problem/#findComment-298855
Share on other sites

I've done the article re-read three times already and it won't work.

 

Did you switch from a server to localhost?

 

Either way if you did let me know, localhost has different cookie rules.

 

Change this part of your code:

<link rel="stylesheet" type="text/css" title="default" href="<?php echo 
isset($_COOKIE['sitestyle'])?$_COOKIE['sitestyle']:'default'; ?>.css" />

 

As everyone pointed out, you were never reading from the cookie and as thorpe (I believe pointed out) you are assuming register_globals was on which is a huge security risk. Give the above a try.

Link to comment
https://forums.phpfreaks.com/topic/59859-styleswitcher-problem/#findComment-299606
Share on other sites

<?php
setcookie ('sitestyle', $_POST['set'], time()+31536000, '/', 'sprites-unlimited.com');
header("Location: " . $_SERVER['HTTP_REFERER']);
?>

 

It sounds like your version of PHP was upgraded recently. Try the above, omit the '0' from the setcookie because that is for the SSL connection, it is assumed to be off and unnecessary. Use $_POST and $_SERVER incase the register_globals was turned off (better that way anyways).

 

Use <?php incase the <? tag was also turned off (as it is depreciated in later versions).

 

Give that a try plus the other post I posted and see what the results are.

Link to comment
https://forums.phpfreaks.com/topic/59859-styleswitcher-problem/#findComment-300012
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.