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
Share on other sites

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.

 

Link to comment
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
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
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
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
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
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.