私のサイトには年齢ゲートが設定されているため、17 歳未満のユーザーはサイトにアクセスできませんが、特定のリンクをブックマークした人が年齢ゲートを通過した後にそのリンクに移動できるようにしたい:
ここに私の年齢ゲートコードがあります:
<?php
session_start();
if(isset($_SESSION['legal'])) { # Check to see if session has already been set
$url = ($_SESSION['legal'] == 'yes') ? 'index.php' : 'message.php';
header ('Location: ' .$url);
}
// If visitor hasn't gone through the age gate - Age Gate function and Set Session//
if(isset($_POST['checkage'])) {
$day = ctype_digit($_POST['day']) ? $_POST['day'] : '';
$month = ctype_digit($_POST['month']) ? $_POST['month'] : '';
$year = ctype_digit($_POST['year']) ? $_POST['year'] : '';
$birthstamp = mktime(0, 0, 0, $month, $day, $year);
$diff = time() - $birthstamp;
$age_years = floor($diff / 31556926);
if($age_years >= 18) {
$_SESSION['legal'] = 'yes';
$url = 'index.php';
} else {
$_SESSION['legal'] = 'no';
// If failed the Age Gate go to specific page
$url = 'message.php';
}
header ('Location: ' .$url);
}
?>
domain/page.php または domain/subdirectory/ に移動したい場合、このコードに何を追加すればよいでしょうか? 通過した後、Age Gate がそこに連れて行ってくれますか? (HTTP リファラーを使用する必要があることはわかっていますが、それを含める方法がわかりません)。
編集して追加: ブラウザーが HTTP リファラーを保持/送信しない場合があることを知っているため、その値を渡さない人のためのソリューションが必要になります。
編集:フォームの送信に基づく年齢計算 -
$day = ctype_digit($_POST['day']) ? $_POST['day'] : '';
$month = ctype_digit($_POST['month']) ? $_POST['month'] : '';
$year = ctype_digit($_POST['year']) ? $_POST['year'] : '';
$birthstamp = mktime(0, 0, 0, $month, $day, $year);
$diff = time() - $birthstamp;
$age_years = floor($diff / 31556926);