note 127638 added to features.cookies
| From: | php dot user1577 at gmail dot com | Date: | Thu, 15 Sep 2022 21:44:32 +0000 |
| Subject: | note 127638 added to features.cookies | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-219582@lists.php.net to get a copy of this message | ||
// Some simple script snippets for processing cookies
// ---------- Page - index.php ----------
<?php
//session_start(); // Note: Session should be startet only after cookies accepted
require "./CookieClass.php";
CookieClass::checkCookiesSet();
CookieClass::setCookiesAllowed();
?>
// ... other HTML Code
<head>
<link href="./bootstrap.min.css" rel="stylesheet">
</head>
<body>
// ... other HTML Code
<div class="container text-center">
<h3 class="mt-5 mb-3">Cookies</h3>
<p>Please accept cookies to enter this website.</p>
</div>
<div class="row">
<div class="col-sm-4"></div>
<div class="col-sm-4">
<form action="index.php" method="post">
<input type="submit"
name="submit"
class="btn btn-warning btn-block"
value="submit"
/>
</form>
</div>
</div>
</body>
// ---------- On all other PHP/HTML pages ----------
<?php
session_start(); // Note: Session should be startet only after cookies accepted
require "./CookieClass.php";
CookieHelper::checkCookiesNotSet();
?>
// ... other HTML Code
// ---------- CookieClass.php ----------
<?php
class CookieClass {
public static function checkCookiesSet()
{
if (isset($_COOKIE["cookieAccepted"]) and $_COOKIE['cookieAccepted'] ==
true) {
header("Location: welcome.php");
}
}
public static function checkCookiesNotSet()
{
if (!isset($_COOKIE["cookieAccepted"]) or $_COOKIE['cookieAccepted'] ==
false) {
header("Location: index.php");
}
}
public static function setCookiesAllowed()
{
if (isset($_POST['submit'])) {
setCookie("cookieAccepted", "true", time() + 3600); // 3600 ist
the activity time in seconds
header("Location: index.php");
}
}
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.173 (proxied: 185.17.14.59)
----
Manual Page -- https://php.net/manual/en/features.cookies.php
Edit -- https://main.php.net/note/edit/127638
Del: integrated -- https://main.php.net/note/delete/127638/integrated
Del: useless -- https://main.php.net/note/delete/127638/useless
Del: bad code -- https://main.php.net/note/delete/127638/bad+code
Del: spam -- https://main.php.net/note/delete/127638/spam
Del: non-english -- https://main.php.net/note/delete/127638/non-english
Del: in docs -- https://main.php.net/note/delete/127638/in+docs
Del: other reasons-- https://main.php.net/note/delete/127638
Reject -- https://main.php.net/note/reject/127638
Search -- https://main.php.net/manage/user-notes.php