Topic: [HELP] Password Protect News

Hi Team,
I would like to implement a way to username/password protect the news on my site.

What I want is to have the page with all the "Short Articles" available to everyone (no login required), however, when a user clicks on a specific news, the user is prompted to insert username and password before reading the "Long Article".

Ideally, the system would generate a session cookie (not persistent) in a way that a user is not requested to type username and password every single time an article is opened.

Any suggestions?

2 (edited by 2014-11-24 16:52:04)

Re: [HELP] Password Protect News

Create another folder on your website and password protect it using .htaccess.
e.g. create a folder called 'private' and put a news page e.g. 'news.php' with normal cutenews includes in this folder.
Lots of websites will show you how to password protect the folder using .htaccess if your website control panel does not have this facility built in.
Use: $PHP_SELF = "private/news.php"; in your newspage include.
Now when a visitor clicks on the full story link on your main newspage it will ask for a password before the fulll story can be read from the private folder newspage.

Read this also:

Re: [HELP] Password Protect News

Damoor, thank you for this.

As you suggested, I created a subfolder and successfully protected it using .htaccess/.htpsswd

Now I have a folder structure similar to this:

|- index.php
|- news.php (newspage - not protected)
|--/news/<cutenews> (CN admin panel)
|--/private/news.php (copy of newspage - protected)

The next step is to update the $PHP_SELF variable. Can you confirm I should make the update as per below?

No changes to this block



    // Play with settings --------------------------------------------------
    $pw = REQ('pw');
    if (isset($pw['PHP_SELF'])&&$pw['PHP_SELF']) $PHP_SELF = $pw['PHP_SELF'];
    if (isset($pw['template'])&&$pw['template']) $template = $pw['template'];

    if (isset($pw['start_from'])&&$pw['start_from']) $start_from = $pw['start_from'];
    if (isset($pw['number'])&&$pw['number']) $number = $pw['number'];
    if (isset($pw['archive'])&&$pw['archive']) $archive = $pw['archive'];
    if (isset($pw['category'])&&$pw['category']) $category = $pw['category'];
    if (isset($pw['ucat'])&&$pw['ucat']) $ucat = $pw['ucat'];
    if (isset($pw['sortby'])&&$pw['sortby']) $sortby = $pw['sortby'];
    if (isset($pw['dir'])&&$pw['dir']) $dir = $pw['dir'];
    if (isset($pw['page_alias'])&&$pw['page_alias']) $page_alias = $pw['page_alias'];
    if (isset($pw['tag'])&&$pw['tag']) $page_alias = $pw['tag'];
    if (isset($pw['user_by'])&&$pw['user_by']) $user_by = $pw['user_by'];

    if (isset($pw['static'])&&$pw['static']) $static = $pw['static'];
    if (isset($pw['reverse'])&&$pw['reverse']) $reverse = $pw['reverse'];
    if (isset($pw['only_active'])&&$pw['only_active']) $only_active = $pw['only_active'];
    if (isset($pw['no_prev'])&&$pw['no_prev']) $no_prev = $pw['no_prev'];
    if (isset($pw['no_next'])&&$pw['no_next']) $no_next = $pw['no_next'];
    // ---------------------------------------------------------------------

    if (isset($_GET['do'])&& $_GET['do'] == "rss") include("rss.php");

Changes below

            <div class="pagedata">

                /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                Here we decide what page to include
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
                if (isset($_GET['search'])&&$_GET['search'])
                    $PHP_SELF = "private/news.php";
                    include ("news/search.php");
                elseif (isset($_GET['do'])&&$_GET['do'] == 'archives')
                    $PHP_SELF = "private/news.php";
                    include ("news/show_archives.php");
                elseif (isset($_GET['do'])&&$_GET['do'] == "stats")
                    echo "You can download the stats addon and include it here to show how many news, comments ... you have"; // include("$path/stats.php");
                    $PHP_SELF = "private/news.php";
                    include ("news/show_news.php");


Re: [HELP] Password Protect News

Yep. Tested and working fine.

Good work Damoor. I appreciate it.

P.S. if you could also help with the other question I had ([HELP] [HACK] Automated Short Story) it would be awesome!