NogDog;11047087 wrote:One downside I see to my preceding "brainstorm" would be if a user bookmarked a URL with the cookie check indicator, or a search engine indexed it. 🙁
Yet another wrinkle. I'm increasingly of the opinion that a cookie-checking page should ONLY check for cookies and do nothing else at all. It could be accessed/displayed in three ways:
as an intermediate page before one enters session-enabled area of a website (i.e., only send users to session area by way of cookie-checking page first)
in an iframe. everybody hates iframes yes but this requires no Javascript and would eliminate the need for us to preserve any $REQUEST vars that might have been passed into the primary page
* via AJAX. sadly, this requires Javascript which I'm not crazy about. On the other hand, it might also keep things nice and tidy on the primary page, eliminating the need to juggle any query string or $POST data that might have been supplied.
NogDog wrote:
1. Do your set cookie, session start, whatever, then
2. Check if the expected cookie(s) is there (whether your count method or just look for a specific cookie (session cookie?)
3. If it's not there, send a refresh header() and/or meta refresh to the same page, but with something in the query string to indicate it's a cookie check
4. If you see from $_GET that it's a cookie check, but there is no cookie, then display your "must enable cookies" message, but don't do the refresh (so we don't get into an infinite refresh loop)
I concocted a little test script to check on this idea:
<?php
session_start();
var_dump($_COOKIE);
?>
A first visit to this page yields an empty $_COOKIE array:
array(0) { }
The second visit shows the cookie:
array(1) { ["PHPSESSID"]=> string(26) "47cath2vaaictkgjjgepm3mhn6" }
In other words, session_start may create a cookie, but it does not immediately redefine the $COOKIE array. This stands to reason, as $COOKIE should only contain cookies passed to the server by the browser and there were none in my case.
This sshows the exact same behavior:
<?php
setcookie("MYCOOKIE", "my cookie's value");
var_dump($_COOKIE);
?>
First access, no cookie, second access, cookie is there.
I'm starting to think it would be nice to have some function, insist_on_cookie(), which would
If a certain $COOKIE["COOKIES_ARE_ENABLED"] = TRUE was found, would do nothing
take a snapshot of any query string parameters, $GET, $REQUEST, whatever
would set a cookie $COOKIE["COOKIES_ARE_ENABLED"] = TRUE
redirect to cookie-check.php, taking care to pass along the snapshot
the script cookie-check.php would:
check to see if $_COOKIE["COOKIES_ARE_ENABLED"] = TRUE
if it exists and is TRUE, simply redirect back to whatever page is captured in the snapshot (or the some default page if no such snapshot exists)
* if the cookie value is not found or is false or whatever, it would halt and display YOU MUST ENABLE COOKIES TO PROCEED and show a TRY AGAIN link which would let the user go back to the page stored in the snapshot
thoughts?
Or might a cookie have been set previously