私の質問は、ユーザーが利用規約ページに同意した後、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>
これは簡単な質問だと思いますが、私は自分が何をしているのか本当にわかりません。ヒントは大歓迎です。