-1

Hi im working with cookies in php and am quite new but i have a button that passes a value through to a function that first echo's it back so i can check if the value is correct and then i upload it set it in the cookie but for some reason the cookie gets a different value.

<input type="button" value="MemberInfo" class="#" id="<?php echo $IGN;?>"onClick="<?php test($IGN);?>"/>

<?php
function test($name)
{
  MakeCookie('MemberInfo', $name);
  echo $name;
} 
function MakeCookie($name, $value)
{
  $cookie_name = $name;
  $cookie_value = $value;
  setcookie($cookie_name, $cookie_value, time()+3600, "/");
}
?>

The Output on the website is But the cookie is this value

  • All this is not happening onClick, it's happening when the page is loaded. The `` doesn't do anything here. And the cookie is likely not getting set, because you're trying to set it after you have already produced HTML output. So that cookie you're seeing is some old value from your previous testing. – deceze May 18 '22 at 08:19

0 Answers0