title: PHP: How to delete a cookie with onclick event from button
body: <p>I'm trying to create a sign out button with php. I might be going about this the completely wrong way, but anyhow I'm trying to delete a cookie on the click of a button.</p>
  
  <pre><code>    &lt;?php 
      function logOut() {
          setcookie('userDetails[username]',"", time()-1200);
      }
  
  
  
  if(isset($_COOKIE["userDetails"])) {
      echo "&lt;table id='rtgLoginBox'&gt;" ;
          echo "&lt;tr&gt;" ;
              echo "&lt;td&gt; Cookie " . $_COOKIE["userDetails"]["username"] . "!";
              echo "&lt;td&gt;&lt;/td&gt;" ;
          echo "&lt;/tr&gt;&lt;tr&gt;" ;
              echo "&lt;td&gt;&lt;input id='rtgLoginBtn' type='submit' value='Log Out' onclick=\"logOut();\" /&gt;&lt;/td&gt;" ;
              echo "&lt;td&gt;";
              echo "&lt;td&gt;&lt;/td&gt;" ;
              echo "&lt;td&gt;&lt;/td&gt;" ;
          echo "&lt;/tr&gt;&lt;tr&gt;" ;
              echo "&lt;td&gt;&lt;/td&gt;" ;
              echo "&lt;td&gt;&lt;/td&gt;" ;
          echo "&lt;/tr&gt;" ;
      echo "&lt;/table&gt;" ;
  } else {
      echo "&lt;table id='rtgLoginBox'&gt;" ;
          echo "&lt;tr&gt;" ;
              echo "&lt;td&gt;&lt;form action='process.php' method='post'&gt;Username:&lt;/td&gt;" ;
              echo "&lt;td&gt;&lt;input name='usernamein' id='rtgUsernameTxt' type='text' size='20' class='rtgSignUpTxt'/&gt;&lt;/td&gt;" ;
          echo "&lt;/tr&gt;&lt;tr&gt;" ;
              echo "&lt;td&gt;Password:&lt;/td&gt;" ;
              echo "&lt;td&gt;&lt;input name='passwordin' id='rtgPasswordTxt' type='password' size='20' class='rtgSignUpTxt' /&gt;&lt;/td&gt;" ;
          echo "&lt;/tr&gt;&lt;tr&gt;" ;
              echo "&lt;td&gt;&lt;/td&gt;" ;
              echo "&lt;td&gt;&lt;input id='rtgLoginBtn' type='submit' value='Log In' /&gt;  &lt;/form&gt;&lt;input id='rtgLoginBtn' type='submit' value='Sign Up' onclick=\"location.href='SignUp.php'\" /&gt;&lt;/td&gt;" ;
          echo "&lt;/tr&gt;&lt;tr&gt;" ;
              echo "&lt;td&gt;&lt;/td&gt;" ;
              echo "&lt;td&gt;&lt;a href='mysite.com'&gt;&lt;p style='padding:0 !important;'&gt;Forgot Login Details?&lt;/p&gt;&lt;/a&gt;&lt;/td&gt;" ;
          echo "&lt;/tr&gt;" ;
      echo "&lt;/table&gt;" ;
      }
  
      ?&gt;
  </code></pre>
  
  <p>As far as I've read online, this should work? I also tried putting the function under the echoed table, but this didn't work either.</p>