Welcome to Geeklog, Anonymous Saturday, December 21 2024 @ 11:06 am EST

Geeklog Forums

Has the user enabled cookies?


Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
I think one of the missed concepts of Geeklog is that it just expects a user to enable cookies as if it's the most natural thing in the world.

So if someone doesn't and, say, tries to log in, Geeklog just shows him the page, to which he tried to log in to, in its guest form - without telling him "you must enable cookies to log in", like you would normally expect.

With that said, I was still wondering if Geeklog has any function that checks if a user's cookie actually exist, but even if so, is it writeable?

Why writeable? Because if someone surfed to my site, enabled cookies, but later disabled them, Geeklog gave orders to keep these cookies for 1 year. This means that during this year, Geeklog will still detect the cookie even if it's disabled (read: not writeable).

The reason I ask this is because I'm trying to make a line of text appear inside some block only if someone didn't enable cookies. I've made it rely on the only cookie Geeklog stores even if someone is not logged in - "LastVisit".

I've written this:
Text Formatted Code

    if ( !isset( $_COOKIE[$_CONF['cookie_lastvisit']])) {
    $retval .= whatever...
}



 

But I also like the user to see it if he does have it set, but it's not writeable (again, maybe it was set a year ago)!

So does Geeklog have a code to the effect of
Text Formatted Code

    if...|| ( !iswriteable( $_COOKIE[$_CONF['cookie_lastvisit']])) {
    $retval .= whatever...
}



 

?
Or maybe it's more like "!isenabled", I don't know...

Thanks!
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Come on, surely there's someone out there who knows how Geeklog checks (or just generally how to check) if a cookie is not only there but actually enabled? Crying or Very sad
 Quote

Status: offline

ronack

Forum User
Full Member
Registered: 05/27/03
Posts: 612
There is probably a JavaScript that will check to see if you have cookies enabled.
Here is one that I found in about 5 seconds.
 Quote

Status: offline

ronack

Forum User
Full Member
Registered: 05/27/03
Posts: 612
Here is some PHP code that will check for cookies enabled.
Text Formatted Code
<?php
error_reporting (E_ALL ^ E_WARNING ^ E_NOTICE);

// Check if cookie has been set or not
if ($_GET['set'] != 'yes') {
        // Set cookie
        setcookie ('test', 'test', time() + 60);

        // Reload page
        header ("Location: checkcookies.php?set=yes");
} else {
        // Check if cookie exists
        if (!empty($_COOKIE['test'])) {
                echo "Cookies are enabled on your browser";
        } else {
                echo "Cookies are <b>NOT</b> enabled on your browser";
        }
}
?>
 
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Both of these scripts reload the page. We are talking about every page in my site...not to mention that "people who have enabled cookies in the past and later disabled them" are like what? 1% of my users?

Most people either always have their cookies enabled for a given site or always have them disabled for it.

You know what? Even if 100% of my users were the former type, I still think that having every page in my site reloading every time it is accessed is insane...

However, we all use Geeklog anyway. Why not using this fact to our advantage? Here's a possible work around: like I said, the only ever present Geeklog cookie is "LastVisit".

If only I knew how Geeklog calculated it, I could simply check if it's updated!

For example, in this very moment (check the original time of this post! Luckily, Geeklog doesn't further confuses us by mentioning when I've edited it...), this site's "LastVisit" cookie indicates 1110366781.

So I would want to use something like:
Text Formatted Code

if...|| ( $_COOKIE[$_CONF['cookie_lastvisit']] != '1110366781') {
    $retval .= whatever...
}

 

Except it should be a copy of Geeklog's own formula for this number.
Get it?

So where can I find the formula?
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Use the source, Luke.

/path/to/geeklog/system/lib-sessions.php

bye, Dirk
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Well, you could have just told me it's just "time()"... Wink

Now it's as simple as
Text Formatted Code

    if ( !isset( $_COOKIE[$_CONF['cookie_lastvisit']]) ||
time() - $_COOKIE[$_CONF['cookie_lastvisit']] > 60 )
    $retval .= whatever...



 


For some reason, it doesn't excatly match time() so I let it have up to a 1 minute delay.
Any idea why is that?

Anyway, disabling previously enabled cookies now triggers the if statement after one reload.

However, if I enable the cookies while already in the site, it takes a couple of refreshes (even if I exit the browser and/or delete its cache) to stop seeing the result of the if statement.
Does anyone know why?
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Well, the if statement still gets executed sometimes even when the user has enabled cookies.

But I've forgotten about the other ever present cookie...lastvisittemp!
Actually, this is the one that I should have used all along because it
expires after a couple of minutes!
Using that knowledge, I can just do:
Text Formatted Code

    if ( !isset( $_COOKIE[$_CONF['cookie_lastvisittemp']]))
 $retval .= whatever...

 

It still takes two refreshes to change cookies from being disabled to enabled (although vice versa is instant).

But at least the if statement isn't triggered anymore for new visitors who have their cookies enabled by default (which are the majority of users).
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Ok, this is driving me insane...

I've used LastVisitTemp because I assumed it must be set if cookies are enabled and unset if not.

Indeed, if cookies are enabled, it's always set...but only for first time visitors!

For return visitors, whose LastVisitTemp exists but expired (read: unset), Geeklog re-sets it as soon as they enter the site...but for some reason it's too late for the if statement, which only detects the un-set mode!

Do you get it? It detects first time visitors after it's set (like it should), but return visitors (when it's expired) before it's set.

And I can't use "ifempty" because once again it'd detect users who have enabled cookies in the past, but disabled them since!
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
I see...it's because it still takes a refresh to detect if lastvisittemp was set.
So if your session has just started, you'll need to press reload in order to make the message dissapear.

I still think it doesn't make much sense to try to put cookies...in order to check if you can put cookies...and then wait one refresh.

This still means that if someone disabled their cookies in the last couple of minutes, he/she won't see the message!

Same thing if I checked for lastvisit itself (using time() - X minutes).
 Quote

All times are EST. The time is now 11:06 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content