RE: [PHP] how to detect the cookie is disabled or enabled?
| From: | Philip Olson | Date: | Mon, 21 Apr 2003 15:25:07 +0000 |
| Subject: | RE: [PHP] how to detect the cookie is disabled or enabled? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-144648@lists.php.net to get a copy of this message | ||
On Mon, 21 Apr 2003, Johnson, Kirk wrote:
> > how to use PHP to detect browser's cookie setting (enabled or
> > disabled)
>
> Check if $_COOKIE['PHPSESSID'] is set on the second page request. One way to
> do this is to do a header() redirect on the first page back to itself. For
> example, if index.php is the first page, then something like this:
>
> if(isset($_GET['redirect')) {
> if(isset($_COOKIE['PHPSESSID'])) {
> // cookies are enabled
> }
> else {
> // cookies are not enabled
> }
> }
> else {
> header('Location: index.php?redirect=true');
> }
The above code assumes sessions are enabled, the session.name
directive is set to PHPSESSID, session.use_cookies is on in
php.ini, and the user accepts session cookies ... not very
generic for simply checking cookie support.
Instead, you should just set a cookie (setcookie()) and see
if it exists on the next page unless you know your session
settings test them instead. Basically if a cookie doesn't
exist (in future http requests) and you had set one, they
don't accept cookies (or at least chose not to accept that
specific cookie :). There really isn't any other way.
Regards,
Philip