Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setcookie() array works on linux, not Windows server!

Status
Not open for further replies.

gelali

Programmer
Nov 6, 2004
7
0
0
US
I have dynamic css.php that user can customize by changing different settings through a form. The form will set a cookie with an array of the settings. This works fine on a linux server. But When I tried it on a windows server, it does not work. When I print the values of the cookie, does not print any thing.

Thanks in advance.

 
Thanks for the reply.

I tried that, but the whole thing stopped working on both servers. when I unserialize and print the values out, nothing prints. If I print before unserializing, it prints the values with some slashes and extra charactors. Tried to add stripslashes, but still same problem!
Any ideas?
 
show code, pls

Bastien

Cat, the other other white meat
 
First, get settings, make array, serialize, and set cookie
<?
$submit= $HTTP_POST_VARS['submit'];
$ColorMix = $HTTP_POST_VARS['ColorMix'];
if ($submit=='submit'){
$fs=$HTTP_POST_VARS['textSize'];
if ($ColorMix=='WhiteOnBlack'){
$fc='white';
$bg='black';
$allSettings=array($fs,$fc,$bg);
setcookie ('sitestyle', serialize($allSettings), time()+31536000, '/', 'domain.com', '0');
header("Refresh: 0; URL=$HTTP_REFERER");
}
?>

Then here unserialize get the settings from the cookie

<?php Header ("Content-type: text/css");

$styleVar = unserialize($HTTP_COOKIE_VARS[sitestyle]);?>
BODY
{
background: <? echo $styleVar[1];?>;
}
 
If you are running under IIS, then it's probably this line:

header("Refresh: 0; URL=$HTTP_REFERER");


There is a flakey interpretation of the HTTP spec that is unique to IIS. Cookies are only sent by IIS when the HTTP response code is 200. Using the Refresh HTTP header likely changes that status to some other value, so IIS doesn't send the cookie.

This is, according to Mi[&cent;]ro$oft, a feature, not a bug.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top