• I would like to protect a (small number of) pages based on a cookie. If the cookie is set, the visitor sees the page. If the cookie is not set, he redirects to some other page, which can be a WP page, external PHP, whatever it takes. That page asks him a question, and if the user says yes it sets the cookie then redirects him to the page he was going to initially. If he says no, it takes him back to the top of the site.

    In other words, I’d like to have a cookie-based age gate.

    The number of pages that I’m trying to protect is relatively small, so it’s not too onerous a task for me to drop a chunk of code onto every page if necessary. It doesn’t have to be elegant, it just has to work.

    I’ve tried making my way through the vast array of plugins available, but I haven’t found quite the right thing yet. Either that, or I didn’t recognize the right thing when it said “Boo!” to me, which is also entirely possible.

    Is there something out there that will let me do what I want without too much work? If not, what’s the best strategy for approaching this? I’m a developer but not much of a web developer, so I have no problem writing whatever code I need… I just don’t know the landscape well enough to be able to come up with a strategy.

Viewing 1 replies (of 1 total)
  • Thread Starter whipartist

    (@whipartist)

    I was able to solve this problem on my own after a bit of experimentation.

    First, I installed Exec-PHP.

    Second, I created a page called Age Gate. It presents the user with a mature content warning, and a yes/no choice. Yes takes you to a page called Cookie Setter. No takes you to the top of the site.

    Cookie setter sets a cookie for my domain called “mature”, and redirects the the category that’s mature.

    Each page of the mature content category has a bit of PHP on the top of it. It checks for the presence of the mature cookie, and if the cookie isn’t set the page redirects to Age Gate.

    A more elegant, generalized solution would pass the destination page through the age gate and cookie setter, then redirect to that specific page rather than to the category. That didn’t matter for my site, but would be necessary for a more generalized blog. It seems possible that blog entries could be wrapped in a bit of PHP that checks for the cookie, and only displays it if the cookie is set.

    I’m guessing I just described the core functionality of a new plugin, but I don’t know enough about wp-guts to do it myself. In any case, putting in a simple age gate is pretty easy.

Viewing 1 replies (of 1 total)
  • The topic ‘Protect certain pages by cookie value’ is closed to new replies.