jackson65 Posted December 21, 2007 Share Posted December 21, 2007 Hello, I have a simple style switcher on my website which worked nicely. My hosting company have switched to php5 and now the style switcher no longer works. the code is from the A List Apart website: <?php setcookie ('sitestyle', $set, time()+31536000, '/','my domain', '0'); header("Location: $HTTP_REFERER"); ?> <link rel="stylesheet" type="text/css" media="screen" title="User Defined Style" href="<?php echo (!$sitestyle)?'defaultstyle':$sitestyle ?>.css" /> Is there a way to make this code "php5 compatible"? Many thanks to anyone who offers a suggestion. Merry Christmas to everyone on the forum. Quote Link to comment https://forums.phpfreaks.com/topic/82660-php-style-switcher-help/ Share on other sites More sharing options...
r-it Posted December 21, 2007 Share Posted December 21, 2007 <?php setcookie ('sitestyle', $set, time()+31536000, '/','my domain', '0'); header("Location: $HTTP_REFERER"); exit; ?> Quote Link to comment https://forums.phpfreaks.com/topic/82660-php-style-switcher-help/#findComment-420412 Share on other sites More sharing options...
jackson65 Posted December 21, 2007 Author Share Posted December 21, 2007 <?php setcookie ('sitestyle', $set, time()+31536000, '/','my domain', '0'); header("Location: $HTTP_REFERER"); exit; ?> SO, by replicating the code, are you saying that it should work with php5? Quote Link to comment https://forums.phpfreaks.com/topic/82660-php-style-switcher-help/#findComment-420438 Share on other sites More sharing options...
PFMaBiSmAd Posted December 21, 2007 Share Posted December 21, 2007 The code does need the exit; statement to prevent the rest of the code from being executed and output while the browser executes the redirect, but that is not the real problem. The code is dependent on register_globals being on and is not php5 problem. $HTTP_REFERER only exists when register_globals are on (check your web server log file for an undefined notice or warning message about $HTTP_REFERER) Change the line to - header("Location: {$_SERVER['HTTP_REFERER']}"); Quote Link to comment https://forums.phpfreaks.com/topic/82660-php-style-switcher-help/#findComment-420440 Share on other sites More sharing options...
jackson65 Posted December 21, 2007 Author Share Posted December 21, 2007 The code does need the exit; statement to prevent the rest of the code from being executed and output while the browser executes the redirect, but that is not the real problem. The code is dependent on register_globals being on and is not php5 problem. $HTTP_REFERER only exists when register_globals are on (check your web server log file for an undefined notice or warning message about $HTTP_REFERER) Change the line to - header("Location: {$_SERVER['HTTP_REFERER']}"); Thanks r-it & PFMaBiSmAd. I changed the .htaccess file to have register_globals on and that did the trick! So I guess php5 has register_globals off by default or else the hosting company has them off for security reasons?? I also changed my code to reflect the suggestions offered, but that didn't work!? When I went back to my original code, it worked!? Thanks for your help....I can go out and have some beers now! CHEERS! Quote Link to comment https://forums.phpfreaks.com/topic/82660-php-style-switcher-help/#findComment-420552 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.