TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

May 18, 2024, 11:38:01 PM

Login with username, password and session length
Members
  • Total Members: 3,886
  • Latest: Grendor
Stats
  • Total Posts: 195,189
  • Total Topics: 21,220
  • Online today: 112
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 1
  • Guests: 84
  • Total: 85
  • @rjen

Anyway to password protect articles?

Started by dry3210, December 18, 2007, 04:22:19 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

dry3210


IchBin

You could add your own custom PHP code to articles. If you google search it I bet you can find something.

lebisol

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"

TimUSA


lebisol

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!

TimUSA

#5
true, what i was suggesting is something like:
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.

dry3210

Quote from: TimUSA on December 18, 2007, 07:56:12 PM
true, what i was suggesting is something like:
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

#7
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


// 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

Innocenzia

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?

IchBin

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

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.

IchBin

No, thats not really possible. You'd have to refresh and redirect the whole page to make another article appear per user group.

Innocenzia

Ah, I see. Thank you for answering my question.

MTF95

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?

IchBin

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.

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

MTF95

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

IchBin

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

 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></a>',
      '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'].'</a>
' : '' , '
' ,  $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

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


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

Quote from: IchBinâ,,¢ on June 03, 2008, 05:55:03 AM
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!!