• Mew

    (@gokumew2)


    Hi. I’m thinking of using a download system script on my site. I can probably customize the template of the script so it looks like a WordPress page. What I need though is a login requirement to access that download section. Is there any coding I can put into the script template so that it will require a user to login in order to access that page?

    I /could/ use a mod so that the script has its own user system but I would rather let my users access it via the WordPress user system so they don’t have to register twice.

    Any help or advice would be appreciated. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • lunabyte

    (@lunabyte)

    If you’re handy with php, you ‘could’ create a system to where someone that was logged into wordpress, they could access the downloads area.

    In a ‘big picture’ reference, you would begin by including the blog header file, which would then ‘essentially’ load wordpress to an extent. Then, you could simply check to see if the user was logged in by using the wordpress functions. You’d basically be looking for the cookies WordPress sets, then running an if else check where if they’re not logged in they are redirected to the login page.

    Depends on what script you’re looking at for downloads.

    But, thanks to the Dev’s for their backend api stuff, things like this are possible.

    Thread Starter Mew

    (@gokumew2)

    Sounds great but besides copying code and writing includes, my PHP knowledge is not very high. ^^; I know I’ve got to make it check for a user session or something but I don’t know how to do that.

    Is there anyone who could tell me the code for this? Thank you!

    PS I’m thinking of using paFileDB for the download script.

    Thread Starter Mew

    (@gokumew2)

    Hmm… Would this work? I found this code in the template for comments.php and changed it a bit.

    <?php // Do not delete these lines
    if (!empty($post->post_password)) { // if there's a password
    if ($_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie
    ?>

    <p><?php _e("You must login to view this page."); ?></p>

    <?php
    return;
    }
    }
    ?>

    So, would this code work in requiring a user to be logged in in order to view the certain page (not created using WP)? And is everything written correctly? I’m not very PHP savvy so I’m not sure what everything, such as <? php return; } } ?> does.

    Any help would be appreciated! Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom page requiring login’ is closed to new replies.