クライアントがクッキーを受け入れたかどうかを保存するクッキーを保存します。現在、次のコードがあります。 index.php
ページでPHP setcookie()が動作していません
:/php/cookies.php
/php/cookies_accepted.php
<?php
setcookie("accepted_cookies","true", time()+60); //Sets the accepted_cookies cookie
$redirect = $_GET['redirect']; //Gets the redirection url from the url
echo $COOKIE_["accepted_cookies"];
echo "<meta http-equiv=\"refresh\" content=\"2; url=".$redirect."\" />"; //Redirects back to the page where the user came from
?>
で
<?php
$redirect = $_GET['redirect']; //Gets the redirection url from the url
echo '
<!DOCTYPE html>
<html>
<a href="cookies_accepted.php?redirect='.$redirect.'">Give me cookies!</a>
</html>'; //Put the accept cookies link on the page
?>
で
<?php
if($_COOKIE["accepted_cookies"] != "true") { // Checks if cookies have been accepted yet, and redirects to cookie page if not
echo "<meta http-equiv=\"refresh\" content=\"1; url=https://website.com/php/cookies.php?redirect=https://website.com/\" />";
}
?>
ただし、クッキーを実際に設定されていないとインデックスが/php/cookies.php
にリダイレクトし続けます。私は何が欠けていますか?
P.S. setcookie関数のtime()はテスト目的のための一時的なものです。
** HeHeHe ** _クライアントがクッキーを受け入れるかどうかを保存するクッキーを保存しますか?そのステートメントに嫌われていませんか? – RiggsFolly
'$ COOKIE_ ['ビットはここに入力されているのか、実際のコードにも入力されていますか? – GentlemanMax
他のページにリダイレクトしたい場合は、PHPを使用しています。[header()を使用してください](http://php.net/manual/en/function.header.php) – RiggsFolly