richardjh Posted May 7, 2009 Share Posted May 7, 2009 Hello I've been using this script to switch a page from ordered to random. However the script that originally worked now does not. The actual script I adapted can be found here: http://www.studiolounge.net/2007/01/06/php-switch/ and if you click on his example this also doesn't work ! (background supposed to change color upon clicking a color link) http://www.studiolounge.net/files/switch/index.php could someone figure out what's wrong please? many thanks for any help or advice R Quote Link to comment https://forums.phpfreaks.com/topic/157235-cookies/ Share on other sites More sharing options...
premiso Posted May 7, 2009 Share Posted May 7, 2009 What changed? Did you upgrade your server, did your host do an upgrade? Did you add any code recently? Post your current code for the index.php, as we cannot help you without seeing current code. Quote Link to comment https://forums.phpfreaks.com/topic/157235-cookies/#findComment-828492 Share on other sites More sharing options...
ignace Posted May 7, 2009 Share Posted May 7, 2009 This script assumes that register_globals = On modify the script to: <?php $sitestyle = isset($_COOKIE['sitestyle']) ? $_COOKIE['sitestyle'] : 'orange'; ?> <html xmlns="http://www.w3.org/1999/xhtml"> <link rel="stylesheet" type="text/css" media="screen" href="<?php echo $sitestyle ?>.css" /> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </meta> </head> <body> <a href="switcher.php?set=red">red</a> <a href="switcher.php?set=green">green</a> <a href="switcher.php?set=blue">blue</a> <a href="switcher.php?set=orange">orange</a> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/157235-cookies/#findComment-828497 Share on other sites More sharing options...
richardjh Posted May 7, 2009 Author Share Posted May 7, 2009 I've downloaded that script and changed the part as per ignace's instructions but alas no joy: could it be anything to do with - header("Location: $HTTP_REFERER"); ? Quote Link to comment https://forums.phpfreaks.com/topic/157235-cookies/#findComment-828572 Share on other sites More sharing options...
premiso Posted May 7, 2009 Share Posted May 7, 2009 What changed? If register_globals was turned off, which it would be a good thing if it was, then you are going to have to convert any item that comes from a form/cookie/get/server variable to the new standard: header("Location: {$_SERVER['HTTP_REFERER']}"); Would be the correct way to write that statement. Quote Link to comment https://forums.phpfreaks.com/topic/157235-cookies/#findComment-828574 Share on other sites More sharing options...
richardjh Posted May 7, 2009 Author Share Posted May 7, 2009 okay this is what i've got now: index.php page is: <?php $sitestyle = isset($_COOKIE['sitestyle']) ? $_COOKIE['sitestyle'] : 'orange'; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <link rel="stylesheet" type="text/css" media="screen" Defined Style" href=" <?php echo (!$sitestyle)?'orange':$sitestyle ?>.css" /> <head> <title>Switcher test</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <a href="switcher.php?set=red">red</a><br> <a href="switcher.php?set=green">green</a><br> <a href="switcher.php?set=blue">blue</a><br> <a href="switcher.php?set=orange">orange</a><br> </body> </html> switcher.php page is: <?php setcookie ('sitestyle', $set, time()+31536000, '/', 'stardedications.com', '0'); header("Location: {$_SERVER['HTTP_REFERER']}"); ?> those two pages along with four .css scripts should toggle the background color for this this test site page: http://stardedications.com/switch/ however, it still fails to change the background color. Quote Link to comment https://forums.phpfreaks.com/topic/157235-cookies/#findComment-828592 Share on other sites More sharing options...
premiso Posted May 7, 2009 Share Posted May 7, 2009 Change this: <?php echo (!$sitestyle)?'orange':$sitestyle ?> To be: <?php echo $sitestyle; ?> Because you set the default value with the code ignace provided to you. See if that gets you up and working. Quote Link to comment https://forums.phpfreaks.com/topic/157235-cookies/#findComment-828596 Share on other sites More sharing options...
richardjh Posted May 7, 2009 Author Share Posted May 7, 2009 Sorry still no joy making that change. in Firefox I can view the cookie information and it seems that the cookie is just not being set: Cookie Information - http://stardedications.com/switch/ * Collapse All * Expand All http://stardedications.com/switch/ 0 cookies Quote Link to comment https://forums.phpfreaks.com/topic/157235-cookies/#findComment-828606 Share on other sites More sharing options...
richardjh Posted May 7, 2009 Author Share Posted May 7, 2009 Hmmmmm. been working on this for hours and still no joy. help!! Quote Link to comment https://forums.phpfreaks.com/topic/157235-cookies/#findComment-828889 Share on other sites More sharing options...
ignace Posted July 6, 2009 Share Posted July 6, 2009 Your index.php has some severe errors, here is the corrected version: <?php $sitestyle = isset($_COOKIE['sitestyle']) ? $_COOKIE['sitestyle'] : 'orange'; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Switcher test</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" type="text/css" media="screen" href="<?php print $sitestyle ?>.css"> </head> <body> <a href="switcher.php?set=red">red</a><br> <a href="switcher.php?set=green">green</a><br> <a href="switcher.php?set=blue">blue</a><br> <a href="switcher.php?set=orange">orange</a><br> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/157235-cookies/#findComment-869905 Share on other sites More sharing options...
thebadbad Posted July 6, 2009 Share Posted July 6, 2009 switcher.php page is: <?php setcookie ('sitestyle', $set, time()+31536000, '/', 'stardedications.com', '0'); header("Location: {$_SERVER['HTTP_REFERER']}"); ?> Use $_GET['set'] instead of $set. Quote Link to comment https://forums.phpfreaks.com/topic/157235-cookies/#findComment-869908 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.