📢 Webサイト閉鎖と移転のお知らせ
このWebサイトは2026年9月に閉鎖いたします。
新しい記事は移転先で追加しております。(旧サイトでは記事を追加しておりません)
| 134行目: | 134行目: | ||
以下の例では、有効期限30分のクッキーに対して、30分前の時間に戻している。<br> | 以下の例では、有効期限30分のクッキーに対して、30分前の時間に戻している。<br> | ||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
time() - 1800 | setcookie("<クッキー名>", "", time() - 1800); | ||
// より安全な方法 | |||
setcookie("<クッキー名>", // 削除するクッキーの名前 | |||
"", [ // クッキーの値を空にする | |||
'expires' => time() - 3600, // 有効期限を30分前前 (1800秒前) に設定して無効化 | |||
'path' => '/', // クッキーが有効なパス ('/'はサイト全体) | |||
'domain' => 'example.com', // クッキーが有効なドメイン | |||
'secure' => true, // HTTPS接続でのみ送信 (true) | |||
'httponly' => true, // JavaScriptからアクセス不可 (true) | |||
'samesite' => 'Strict' // クロスサイトリクエストを制限 (Strictは同一サイトのみ) | |||
]); | |||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
| 140行目: | 151行目: | ||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
<?php | <?php | ||
if(isset($_COOKIE["visited"])) | if(isset($_COOKIE["visited"])) $count = $_COOKIE["visited"] + 1; | ||
else $count = 1; | |||
else | |||
if($count > 3) | if($count > 3) { | ||
setcookie("visited", $count, time() - 1800); | setcookie("visited", $count, time() - 1800); | ||
$count = 1; | $count = 1; | ||
} | } | ||
else | else { | ||
setcookie("visited", $count); | setcookie("visited", $count); | ||
} | } | ||