Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome, Guest. Please login or register.
Did you miss your activation email?

May 29, 2020, 06:10:05 PM

Login with username, password and session length
Members
Stats
  • Total Posts: 190011
  • Total Topics: 20832
  • Online Today: 288
  • Online Ever: 917
  • (January 21, 2020, 09:02:26 AM)
Users Online
Users: 0
Guests: 91
Total: 91

Author Topic: Anyway to password protect articles?  (Read 12922 times)

0 Members and 1 Guest are viewing this topic.

dry3210

  • Guest
Anyway to password protect articles?
« on: December 17, 2007, 09:22:19 PM »
Anyway to password protect articles?

Offline IchBin™

  • Developer
  • *
  • Posts: 16228
    • My Website
Re: Anyway to password protect articles?
« Reply #1 on: December 17, 2007, 09:25:19 PM »
You could add your own custom PHP code to articles. If you google search it I bet you can find something.

lebisol

  • Guest
Re: Anyway to password protect articles?
« Reply #2 on: December 18, 2007, 10:27:36 AM »
Consider htaccess
http://www.htmlgoodies.com/tutorials/getting_started/article.php/3479531
or as Ich said enter a small php code (you would have convert all articles to php) to check "if user member group =x Then echo ....article ...Else "sorry"

Offline TimUSA

  • Full Member
  • ***
  • Posts: 211
Re: Anyway to password protect articles?
« Reply #3 on: December 18, 2007, 11:49:31 AM »
why not restrict it to a member group?

lebisol

  • Guest
Re: Anyway to password protect articles?
« Reply #4 on: December 18, 2007, 12:42:58 PM »
unlike forum baords articles are public...ACls only apply to edit/add/submit no 'view'.
I think he is looking for just a password protection to articles for guests and memebers...suppose the author will say more...
All the best!

Offline TimUSA

  • Full Member
  • ***
  • Posts: 211
Re: Anyway to password protect articles?
« Reply #5 on: December 18, 2007, 12:56:12 PM »
true, what i was suggesting is something like:
Code: [Select]
global $user_info;

if (count(array_intersect(array(1,9,10,11,12,13), $user_info['groups'])))
{
echo '***Your HTML here***';
}

This will show your article only to the selected member groups. So instead of a password, you would change their member group.
« Last Edit: December 18, 2007, 01:00:01 PM by TimUSA »

dry3210

  • Guest
Re: Anyway to password protect articles?
« Reply #6 on: January 05, 2008, 06:49:06 PM »
true, what i was suggesting is something like:
Code: [Select]
global $user_info;

if (count(array_intersect(array(1,9,10,11,12,13), $user_info['groups'])))
{
echo '***Your HTML here***';
}

This will show your article only to the selected member groups. So instead of a password, you would change their member group.

That should work then! 

Yeah basically I wanted it so some articles are viewable by all..and others are restricted some how membergroup or password

evilicy

  • Guest
Re: Anyway to password protect articles?
« Reply #7 on: January 17, 2008, 06:46:54 PM »
I know this was already resolved but wanted to share this code anyways and figure might as well post it here since it is related.

Remember the old Javascript "the gate keeper"? that pw protected pages I used to get a kick out of it. Well here it is again with the same fun novelty but in php for php articles.

DEMO
Password is: password

Code: [Select]
// Define your password

$password = "password";



if ($_POST['txtPassword'] != $password) {

echo '<img src="http://darkvoid.org/images/keeper.gif">

<form name="form" method="post" action="'; $_SERVER['PHP_SELF']; echo '">

<p><label for="txtpassword">Password:</label>

    <br /><input type="password" title="Enter your password" name="txtPassword" /></p>

<p><input type="submit" name="Submit" value="Enter Password" /></p>

</form>';

}

else {

echo "<p>This is the protected page. Your private content goes here.</p>";

}

PS

I didn't write the original gate keeper script or the php code provided. I simply googled the code and added the novelty of the Gate keeper to it :P
« Last Edit: January 17, 2008, 06:49:44 PM by evilicy »

Innocenzia

  • Guest
Re: Anyway to password protect articles?
« Reply #8 on: January 20, 2008, 12:33:54 PM »
Is there a way to make the information in an article viewable only for nonmembers, let say i want it to say: "please join.  blaha, blaha.." then i wouldn't want the members to see it, in stead i want the members to see: "Hi Member. blaha, blaha.." so the same article, but different text for members and nonmembers?

Offline IchBin™

  • Developer
  • *
  • Posts: 16228
    • My Website
Re: Anyway to password protect articles?
« Reply #9 on: January 20, 2008, 12:36:26 PM »
Code: [Select]
if ($context['user']['is_guest'])
    echo 'The code here for a guest that you want';

if ($context['user']['is_logged'])
    echo 'The code here for logged in users';

Innocenzia

  • Guest
Re: Anyway to password protect articles?
« Reply #10 on: January 22, 2008, 09:52:27 AM »
Thank you! :) Is it possible to take it to the next step, and instead of showing different text actually adding different articles, in the existing article? So the guest will see one article, and members another, and the administrator doesn't have to go into the top-article to change the code, so that the guest-article and the member-article could be written by different people.
And taking another step further into it all, is it possible to add another article to all with admin-access, and another to a certain user. For example, i want to add an article only viewable to the member named Jenny? Is there some kind of list with all this variables written somewhere?  I'm sorry for bothering with questions but I'm trying to learn more about this and is trying to get it as easy as possible for my other administrators to change articles, and they would mess the php-article up totally I'm afraid.

Offline IchBin™

  • Developer
  • *
  • Posts: 16228
    • My Website
Re: Anyway to password protect articles?
« Reply #11 on: January 22, 2008, 01:23:58 PM »
No, thats not really possible. You'd have to refresh and redirect the whole page to make another article appear per user group.

Innocenzia

  • Guest
Re: Anyway to password protect articles?
« Reply #12 on: January 24, 2008, 10:43:20 AM »
Ah, I see. Thank you for answering my question.

MTF95

  • Guest
Re: Anyway to password protect articles?
« Reply #13 on: June 02, 2008, 05:11:56 AM »
What about the users whitout permission, what will they see?
There's no error message in the code..
Could I do like this:

global $user_info;

if (count(array_intersect(array(allowed groups), $user_info['groups'])))
{
   echo 'Allowed groups will se this.';
}
global $user_info;

if (count(array_intersect(array(not allowed groups), $user_info['groups'])))
{
   echo 'Not allowed groups will se this.';
}


Or is there a simpler way?

Offline IchBin™

  • Developer
  • *
  • Posts: 16228
    • My Website
Re: Anyway to password protect articles?
« Reply #14 on: June 02, 2008, 07:35:12 AM »
Users without permissions are guests. They will not see anything unless you specify something for theme  to see. You have some if statements for the groups. Add an else statement for guests.

Code: [Select]
else{
    echo 'all stuff here for guests if the user is not in a group.';
}

MTF95

  • Guest
Re: Anyway to password protect articles?
« Reply #15 on: June 02, 2008, 10:42:27 PM »
Now the articel just shows
Parse error: syntax error, unexpected T_ELSE in /home/simmarcu/public_html/Sources/Load.php(1870) : eval()'d code(209) : eval()'d code on line 11

Offline IchBin™

  • Developer
  • *
  • Posts: 16228
    • My Website
Re: Anyway to password protect articles?
« Reply #16 on: June 02, 2008, 10:55:03 PM »
Change the flux capacitor to zero, hit the take off button and make sure you reach 88 miles per hour!









Or help us help you by giving some information to work with. Preferably the code you are using so we can see the error you've made. :)

MTF95

  • Guest
Re: Anyway to password protect articles?
« Reply #17 on: June 03, 2008, 11:49:24 AM »
 global $user_info;

if (count(array_intersect(array(1,14,15,17,22), $user_info['groups'])))
{
   echo '

<B>Personalsidorna är ännu under uppbyggnad.</B>


Nedan ser du all personal på sidan, alltså dina kollegor!
';

else{
    echo 'all stuff here for guests if the user is not in a group.';
}
<span class="smalltext">Dessa medelmar är en del av Sim-Marcus personal och hjälper till på olika delar av sidan.</span>
';
}
 global $txt, $scripturl, $user_info;
   global $context, $modSettings, $ID_MEMBER;
   global $board_info, $settings, $db_prefix;

/////////////////////////////////////////////////////////////////  Enter the desired groups in order of Appearance
   $groups_list = array(1, 17, 14, 15, 22);
/////////////////////////////////////////////////////////////////

          echo '<table align="center" width="95%" cellpadding="0" cellspacing="0"><tr>
                <td style="border-bottom: 2px solid #d0d0d0; padding-bottom: 4px; ">
      


      </td></tr></table>';



   foreach($groups_list as $groupnumber)
   {

   $loaded_ids = array();
    $user_profile=array();
    $memberContext=array();
    $profile=array();
    $context['TPortal']['team']=array();

   // get the name of the group
   $request = db_query("
                        SELECT groupName, onlineColor FROM {$db_prefix}membergroups WHERE ID_GROUP=".$groupnumber, __FILE__, __LINE__);
      $row = mysql_fetch_assoc($request);
      $groupname = $row['groupName'];;
      $grpcolor=$row['onlineColor'];
      mysql_free_result($request);

   $select_columns = "
         IFNULL(lo.logTime, 0) AS isOnline, IFNULL(a.ID_ATTACH, 0) AS ID_ATTACH, a.filename, a.attachmentType,
         mem.personalText, mem.avatar, mem.ID_MEMBER, mem.memberName,
         mem.realName,mem.lastLogin, mem.websiteTitle, mem.websiteUrl, mem.location,   
                        mem.posts,
                        them.value AS teamtext";
   $select_tables = "
         LEFT JOIN {$db_prefix}log_online AS lo ON (lo.ID_MEMBER = mem.ID_MEMBER)
         LEFT JOIN {$db_prefix}attachments AS a ON (a.ID_MEMBER = mem.ID_MEMBER)
                        LEFT JOIN {$db_prefix}themes AS them ON (mem.ID_MEMBER = them.ID_MEMBER AND them.variable = 'teamtext' AND them.ID_THEME=1)";

   // Load the member's data.
   $request = db_query("
         SELECT$select_columns
         FROM {$db_prefix}members AS mem$select_tables
         WHERE mem.ID_GROUP = $groupnumber
                        ORDER BY mem.memberName ASC", __FILE__, __LINE__);
   $new_loaded_ids = array();
   while ($row = mysql_fetch_assoc($request))
   {

         $avatar_width = '';
         $avatar_height = '';

      $context['TPortal']['team'][] = array(
      'username' => $row['memberName'],
      'name' => $row['realName'],
      'groupname' => $groupname,
      'posts' => $row['posts'],
      'location' => $row['location'],
      'href' => $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
      'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '" title="' . $txt[92] . ' ' . $row['realName'] . '"><font color="'.$grpcolor.'">' . $row['realName'] . '</font>[/url]',
      'blurb' => $row['personalText'],
      'avatar' => array(
         'name' => $row['avatar'],
         'image' => $row['avatar'] == '' ? ($row['ID_ATTACH'] > 0 ? '<img  src="' . (empty($row['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $row['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" class="avatar2" border="0" />' : '') : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" class="avatar2" border="0" />' : '<img src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" class="avatar2" border="0" />'),
         'href' => $row['avatar'] == '' ? ($row['ID_ATTACH'] > 0 ? (empty($row['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $row['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) : '') : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar']),
         'url' => $row['avatar'] == '' ? '' : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar'])
      ),
      'last_login' => empty($row['lastLogin']) ? $txt['never'] : timeformat($row['lastLogin']),
      'last_login_timestamp' => empty($row['lastLogin']) ? 0 : forum_time(0, $row['lastLogin']),
      'website' => array(
         'title' => $row['websiteTitle'],
         'url' => $row['websiteUrl']),
      'online' => array(
         'is_online' => $row['isOnline'],
         'text' => &$txt[$row['isOnline'] ? 'online2' : 'online3'],
         'image_href' => $settings['images_url'] . '/' . ($row['isOnline'] ? 'useron' : 'useroff') . '.gif',
      ),
      'teamtext' => $row['teamtext'],
   );


   }
   mysql_free_result($request);





      echo '<table align="center" width="95%" cellpadding="5" cellspacing="5"><tr>
            <td colspan="4" style="border-bottom: 2px solid #d0d0d0; padding-bottom: 4px; "><h2>' . $groupname . '</h2>
            </td></tr><tr><td colspan="4">
 </td></tr><tr>';


        $newrow=0;
   foreach($context['TPortal']['team'] as $team)
        {
            echo '
<td valign="top">'.$team['avatar']['image'].'</td>
<td valign="top" width="50%" class="middletext" style="padding: 5px;">
<h2 style="margin-top: 0; margin-bottom: 6px;">'.$team['link'].'</h2>
Last seen: '.$team['last_login'].'

Posts: '.$team['posts'].'

Position: '.$team['groupname'].'

' , !empty($team['location']) ? 'Location: '.$team['location'].'
' : '' , '
' , !empty($team['website']['title']) ? 'Website: <a href="'.$team['website']['url'].'" target="_blank">'.$team['website']['title'].'[/url]
' : '' , '
' ,  $team['online']['is_online'] ? '<img src="'.$team['online']['image_href'].'" alt="" /> '.$team['online']['text'].'
' : $team['online']['text'].'
' , '

' , !empty($team['blurb']) ? '- '.$team['blurb'].'
' : '' , '

' ,  !empty($team['teamtext']) ? $team['teamtext'].'
' : '' , '

    </div></td>';
            $newrow++;
            if($newrow>1){
               $newrow=0;
               echo '</tr><tr><td colspan="4">

 </td></tr><tr>';
            }
        }
    }
echo '</tr></table>';

JPDeni

  • Guest
Re: Anyway to password protect articles?
« Reply #18 on: June 03, 2008, 01:08:38 PM »
It would be a lot easier to read if you would use [ code ] tags, but it looks like you're missing a closing } in your first "if" statement. It should be

Code: [Select]
if (count(array_intersect(array(1,14,15,17,22), $user_info['groups'])))
{
    echo '
  <B>Personalsidorna är ännu under uppbyggnad.</B>
  Nedan ser du all personal pÃ¥ sidan, alltsÃ¥ dina kollegor!';
}
else{
    echo 'all stuff here for guests if the user is not in a group.';
}
<span class="smalltext">Dessa medelmar är en del av Sim-Marcus personal och hjälper till på olika delar av sidan.</span>
';

Polymath

  • Guest
Re: Anyway to password protect articles?
« Reply #19 on: September 23, 2008, 10:50:27 PM »
Change the flux capacitor to zero, hit the take off button and make sure you reach 88 miles per hour!

 :2funny:  That didn't work!!