Forum Moderators: coopster

Message Too Old, No Replies

Cookie store

cookie

         

gonny

11:08 pm on Dec 19, 2007 (gmt 0)

10+ Year Member




<?
switch($_GET['set']) {
case 'new':
new();
break;
default:
start();
break;
}
function start() {
if(isset($_COOKIE['style5']))
{$stili=$_COOKIE['style5'];}
else
{$stili="default";}
echo "<a href=\"index.php?set=new\">click here to change!</a>";
$es = $stili;
echo "$es";
}
function new() {
$in = $_POST['set'];
setcookie ('style5', $in, time()+31536000, '', 'domain.net', '0');
header("Location: $HTTP_REFERER");
}
?>

I have made this to store a value in cookie browser but doesnt work. What's the problem?

pragone

12:00 am on Dec 20, 2007 (gmt 0)

10+ Year Member



I guess it's the:

$in = $_POST['set'];

You're using POST instead of GET

gonny

5:18 pm on Dec 20, 2007 (gmt 0)

10+ Year Member



ohh I'm confused about this... lol
anyway thnx a lot

coopster

5:28 pm on Dec 20, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



A link that you click, such as one in an anchor element like you have here ...
<a href="index.php?set=new">click here to change!</a>

... is by nature a GET request. You are trying to read the value of the "set" named variable index from the PHP $_POST superglobal as opposed to the $_GET superglobal.

BTW, Welcome to WebmasterWorld, pragone.