I'm having a strange problem, I can't write a cookie
I have the following code
<?php
$backcolor = $_POST['backcolor'];
$textcolor = $_POST['textcolor'];
setcookie("backcolor", $backcolor, time()+3600);
setcookie("textcolor", $textcolor, time()+3600);
header("Location: http://localhost/php/cookies.sps");
exit;
?>
I get the the POST data from the 'cookies.sps' where I send my browser back.
And my Register_globals is off, I use PWS
And as in ASP
How can same cookie name can be given a different name=value
like response.cookies("color")("textcolor") = "black"
Is the below code correct for PHP?
<?php
setcookie("color['backcolor']", $backcolor, time()+3600);
setcookie("color['textcolor']", $textcolor, time()+3600);
?>
Please help!
Cookie Problem
Moderators: egami, macek, gesf
-
- New php-forum User
- Posts: 13
- Joined: Mon Mar 17, 2003 6:38 am
Try this...
<?php
$bc = $backcolor;
$tc = $textcolor;
setcookie("backcolor", $bc, time()+3600) &&
setcookie("textcolor", $tc, time()+3600) &&
header("Location: http://localhost/php/cookies.sps");
exit;
?>
I never tried to work my scripts in a localhost, why don't you try uploading them first. :P
And remember that the code has to be above the <html> tag or it wont work!
By the way... You'r using a form I hope??!!
<?php
$bc = $backcolor;
$tc = $textcolor;
setcookie("backcolor", $bc, time()+3600) &&
setcookie("textcolor", $tc, time()+3600) &&
header("Location: http://localhost/php/cookies.sps");
exit;
?>
I never tried to work my scripts in a localhost, why don't you try uploading them first. :P
And remember that the code has to be above the <html> tag or it wont work!
By the way... You'r using a form I hope??!!
-
- New php-forum User
- Posts: 191
- Joined: Wed Jan 29, 2003 7:11 am
- Location: UK
- Contact:
or
$c_array = array(backcolour => $_POST['backcolour'], textcolour => $_POST['textcolour']);
$c_data = serialize($c_array);
setcookie('colour_cookie',$c_data,time()+3600,"/","www.domain.com");
.......
if($_COOKIE['colour_cookie'] !== "")
{
$c_data = unserialize(stripslashes($_COOKIE['colour_cookie']));
echo 'background = '.$c_data['backcolour'];
}
might need if($colour_cookie !== "") though as the name might be globalized. Also depends upon your build version of PHP.
$c_array = array(backcolour => $_POST['backcolour'], textcolour => $_POST['textcolour']);
$c_data = serialize($c_array);
setcookie('colour_cookie',$c_data,time()+3600,"/","www.domain.com");
.......
if($_COOKIE['colour_cookie'] !== "")
{
$c_data = unserialize(stripslashes($_COOKIE['colour_cookie']));
echo 'background = '.$c_data['backcolour'];
}
might need if($colour_cookie !== "") though as the name might be globalized. Also depends upon your build version of PHP.
avatar image based upon nasas apod (only updates if I post though)