Jump to content

cookies


richardjh

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/157235-cookies/
Share on other sites

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>  

Link to comment
https://forums.phpfreaks.com/topic/157235-cookies/#findComment-828497
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/157235-cookies/#findComment-828574
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/157235-cookies/#findComment-828592
Share on other sites

  • 1 month later...

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>

Link to comment
https://forums.phpfreaks.com/topic/157235-cookies/#findComment-869905
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.