在用户同意条款和条件表格后如何设置cookie?

我的问题是,在用户同意条款和条件页面后,如何设置cookie? 我打算添加这段代码
<?php //Calculate 30 days in the future    
//seconds * minutes * hours * days + current time    
$inOneMonth = 60 * 60 * 24 * 30 + time(); 
setcookie('lastVisit', date("G:i - m/d/y"), $inOneMonth); 
?>
对于下面的代码,但取决于我把它放在哪里我要么打破javascript或在页面刷新cookie设置(即使条款和条件尚未达成一致)。
<?php
// Get the user's ultimate destination
$dest = $_GET['dest'];
// Show the terms and conditions page
//check for cookie
if(isset($_COOKIE['lastVisit']))
    $visit = $_COOKIE['lastVisit']; /* Add redirect later   document.location.href='http://<?php echo $dest; ?>';   add redirect code later*/
else
    echo "No cookies present-remove this msg later";
?>

<HTML>
  <HEAD>
    <TITLE>User Agreement</TITLE>
    <script language="javascript">

function valbutton(thisform) {
// validate myradiobuttons
  myOption = -1;
  for (i=thisform.myradiobutton.length-1; i > -1; i--) {
    if (thisform.myradiobutton[i].checked) {
      myOption = i;
    }
  }
  if (myOption == -1) {
   alert("You must choose either YES or NO");
   return false;
  }
  if (myOption == 0) {
   alert("You must agree to the Terms and Conditions to download");
   return false;
  }
  thisform.submit(); // this line submits the form after validation
}
</script>

  </HEAD>
  <BODY>
    <H1> Terms and Conditions </H1>
    <P>Before downloading you must agree to be bound by masking tape</P>
<form name="myform" action="http://<?php echo $dest; ?>"> 
<input type="radio" value="1st value" name="myradiobutton" />NO<br />
<input type="radio" value="2nd value" name="myradiobutton" />YES<br />
<input type="submit" name="submitit" onclick="valbutton(myform);return false;" value="ANSWER" />
</form>

  </BODY>
</HTML>
我确信这是一个简单的问题,但我真的不知道我在做什么。任何提示都非常感谢。     
已邀请:
更好的方法是在服务器端评估/验证输入。 通常你需要这样做,因为安全原因,Javascript验证只是为了用户友好,而不是为了安全!在您的情况下,没有真正的用户输入,因此没有直接威胁。 通常通过访问$ _POST数组并根据需要验证不同的表单字段来验证输入。当整个验证链成功时,设置cookie!     
还有一件事... 看看你的setcookie电话:
setcookie('lastVisit', date("G:i - m/d/y"), $inOneMonth); 
如果认为正确的方法是
setcookie('lastVisit', date("G:i - m/d/y", $inOneMonth)); 
    

要回复问题请先登录注册