• hi

    i’d like to create a page that only registerd users (who are logged-in) will be able to see it.

    if you are not registered/loged-in you will be redirected to a login/register page.

    if you are already registered and loged-in you will see the requested page.

    how do i do it?

    thanks

    lenny

Viewing 12 replies - 1 through 12 (of 12 total)
  • Take a look at my Simple access Control plugin. It’s intended for exactly that purpose.

    It currently doesn’t do the redirect, it just advises the user to login.

    /peter

    All you need is to add this function to the top of the page you want to require authentication on. It will take care of the rest.

    <?php auth_redirect(); ?>

    If the user is logged in they will see the page normally, otherwise they will be redirected to login and then directed back to the page they left once they are successfully authenticated.

    This function sends headers so you’ll need to make sure you use it early enough. I haven’t tested this, but you can probably hook into the init action and run the code from there.

    Thread Starter kapara

    (@kapara)

    This function sends headers so you’ll need to make sure you use it early enough. I haven’t tested this, but you can probably hook into the init action and run the code from there.

    sorry, i’m not a programmer, could you please write … slower, so i can understand?

    could you please explain what i should do?

    thank you very much

    lenny

    Thread Starter kapara

    (@kapara)

    to pkwooster:
    thanks, i’ll try it

    lenny

    Thread Starter kapara

    (@kapara)

    to pkwooster:

    thanks, i DL and installed, i have a couple of questions but it looks great.

    i’ll be in touch

    thanks

    lenny

    @kapara Try going into your theme’s header.php and pasting this code at the very tip top:

    <?php if ( is_page( $PAGE_ID ) ) auth_redirect(); ?>

    Replace $PAGE_ID with the ID of the page that you’re trying to restrict to members only. You should be able to find this page id easily by editing the page in your WordPress admin, then looking at the URL and finding the post=# bit where # is the page id.

    Edit: Added PHP tags.

    Hi Lenny,

    I got your message and will add the ability to specify whether the menu should be filtered and a link to wp-login in the “not logged “in text.

    /peter

    I originally used User Access Manager. That was the inspiration to write Simple Access Control. UAM is way more than you need, for more complex membership sites it’s great.

    Unlike UAM Simple Access Control does not add any tables to your database and the code is simple enough that you can extend it if you need to.

    I’ve just updated Simple Access Control to provide the menu control and login link.

    /peter

    Thanks pkwooster.

    I’ll try your plugin out too.

    What is the benefit of it not adding tables to the database? Doesn’t that mean it won’t be backed up with the normal database backup?

    It uses the standard WordPress tables wp_options and wp_usermeta. The advantage is that you don’t end up with database clutter.
    /peter

    One another note about UAM. Even if you only activated it, you are getting already about 50 extra database queries. After creating user groups it adds more and more database queries for each created user group.
    For example, the Members plugin doesn’t add any one query.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘page only for registered users’ is closed to new replies.