Welcome Guest, Not a member yet? Register   Sign In
Checking for non-logged in users before showing cached pages [Adv.]
#3

[eluser]Xeoncross[/eluser]
Thanks for the reply. My topic apparently, is relativity novel, which is why I can't fine much information in it. Let me try to explain it further.

Assume:
User Auth library uses sessions
Sessions are stored in DB
Checking a users session requires loading DB & user lib.

Lets say you have a page like a blog post. Most people will see the post and comments. Admins will see edit links next to each comment. Here we have two forms of the same page. Normal CI page caching checks for the existence of a cache BEFORE loading the system - so your user lib, sessions, and database are not loaded to even be checked. Therefore, if you create a cache for a guest - then an admin will also see that page (without the edit links) because at this point in the system we can't tell an admin from a guest.

The solution to this problem is to load the user lib, sessions, and database and THEN check to see if it is alright to show the cache. This is inefficient.

So my idea is to base the check off of something that can be accessed without loading all this, something that is native to PHP, something like... cookies. Now hear my cookie idea and keep in mind that this has nothing to do with actually logging people in based on this cookie.


A User logs in and is given a session cookie along with a cookie called "logged_in" which is set to true. This cookies only point in life is to give us a heads up that the user is *probably* logged in. All guests and non-logged in people have no cookie (unless they manually create one in their browser).

So back to the blog post. First we check for isset($_COOKIE['logged_in']). If it is found then we know that this user has probably logged in so we can justify wasting our resources to load the DB, sessions, and user lib to check for sure. If this cookie is not found then we know they couldn't possible be logged in so we show the cache.

So if a user creates a $_COOKIE['logged_in'] then our system wastes time to show them fresh pages (but still don't see edit links), admins with valid $_COOKIE['logged_in'] see fresh pages (with links), and everyone else sees caches.

make sense?


Messages In This Thread
Checking for non-logged in users before showing cached pages [Adv.] - by El Forum - 09-21-2009, 07:28 PM



Theme © iAndrew 2016 - Forum software by © MyBB