Mikael
08-22-2006, 11:56 AM
When I click on a number, I like it to switch from 0 to 1 or vice versa. Now both numbers gets switched. Also, when I reload the page, the numbers switch.
I only like the number that I click on to switch. And reloading shouldn't affect the numbers. I think that looking at the code simply explains what I try to do.
What am I doing wrong?
The filename is test.php
<html>
<body>
<?php function uSwitch($cid)
{
if (isset($_COOKIE[$cid]))
if ($_COOKIE[$cid]=="0")
setcookie($cid, "1", time()+7200);
else
setcookie($cid, "0", time()+7200);
else
setcookie($cid, "1", time()+7200);
}
?>
<?php function uPrint($cid)
{
if (isset($_COOKIE[$cid]))
echo $_COOKIE[$cid];
else
echo '0';
}
?>
Welcome!<br>
<br>
user1: <a href="test.php" onClick="<?php uSwitch("u1"); ?>">
<?php uPrint("u1");?></a><br>
user2: <a href="test.php" onClick="<?php uSwitch("u2"); ?>">
<?php uPrint("u2");?></a>
</body>
</html>
I only like the number that I click on to switch. And reloading shouldn't affect the numbers. I think that looking at the code simply explains what I try to do.
What am I doing wrong?
The filename is test.php
<html>
<body>
<?php function uSwitch($cid)
{
if (isset($_COOKIE[$cid]))
if ($_COOKIE[$cid]=="0")
setcookie($cid, "1", time()+7200);
else
setcookie($cid, "0", time()+7200);
else
setcookie($cid, "1", time()+7200);
}
?>
<?php function uPrint($cid)
{
if (isset($_COOKIE[$cid]))
echo $_COOKIE[$cid];
else
echo '0';
}
?>
Welcome!<br>
<br>
user1: <a href="test.php" onClick="<?php uSwitch("u1"); ?>">
<?php uPrint("u1");?></a><br>
user2: <a href="test.php" onClick="<?php uSwitch("u2"); ?>">
<?php uPrint("u2");?></a>
</body>
</html>