[Quasi-MOD] Block Guests from Viewing ANY Page

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment! No new topics are allowed in this forum.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: MOD Development Forum rules

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.
discipleao
Registered User
Posts: 63
Joined: Thu Jan 02, 2003 4:58 am

[Quasi-MOD] Block Guests from Viewing ANY Page

Post by discipleao »

Not really a MOD but I didn't know where else to put this.
And IF it is a MOD, then the credit goes to the author of the Hide All User Info MOD:

Code: Select all

darbyrob rob@wombatmedia.com (Rob Chojnacki)


The ONLY reason I am posting this was when I looked for the solution here, I found other users also looking, and very few answers.

But anyway, for those interested:
Here's how I let only logged in users see certian pages on my site.

Code: Select all

OPEN: 
//The .php file you want to protect

FIND:

//
// End session management
//

ADD AFTER:
//
// Block guests from viewing page - Redirect to login
//
if ( !$userdata['session_logged_in'] ) {
   $header_location = ( @preg_match("/Microsoft|WebSTAR|Xitami/", getenv("SERVER_SOFTWARE")) ) ? "Refresh: 0; URL=" : "Location: ";
   header($header_location . append_sid("login.".$phpEx."?redirect=PAGENAME.".$phpEx, true));
   exit;
}
//
// End Block guests
//

FIND:
redirect=PAGENAME.

//change to the name of the page you are trying to protect, minus the php extension ex. example.php = example.
That's it.
Bradman
Registered User
Posts: 84
Joined: Mon Nov 11, 2002 6:39 am
Location: Ledyard, CT
Contact:

Post by Bradman »

Isn't this done through the admin panel by setting the permissions for each forum? No mod needed, just set it to not be viewable by guests and they won't even know it's there.
carosel
Registered User
Posts: 24
Joined: Thu Sep 19, 2002 8:12 pm
Location: Matthews, NC
Contact:

Post by carosel »

Bradman wrote: Isn't this done through the admin panel by setting the permissions for each forum? No mod needed, just set it to not be viewable by guests and they won't even know it's there.

My thoughts exactly -- can't the same be done by editing the permissions of your forum? If you leave it to where guests can't view, then they'll get an empty forum view until they register, if you were to disable guests from viewing any page.

Though, if you're trying to disable the view of any page, which (since it's 12:43am and I'm sleepy) may be what you're getting at, good deal. This is kind of like the Restrict Memberlist/Usergroup Pages mod, no? :)
The world is not yours to give; your heart is.
discipleao
Registered User
Posts: 63
Joined: Thu Jan 02, 2003 4:58 am

Post by discipleao »

Yeah, sorry I should have been more clear - the point here was to restrict viewing of ANY page, including NON-forum pages...

It's just a quick way to force a login before displaying a page.
For example:

I am making a section called Articles.
Anyone can read the articles.
Any USER can upload articles.
When you hit the link to the upload section, you are forced to login, so that an unregistered guest cannot upload to your server.
carosel
Registered User
Posts: 24
Joined: Thu Sep 19, 2002 8:12 pm
Location: Matthews, NC
Contact:

Post by carosel »

Very good idea. :)
I like it a lot -- it makes things more secure and private for your members. But, wouldn't you have to do the define phpbb thing for your own new pages (articles and such)..

Code: Select all

define('IN_PHPBB', true);
..in the page to have this work at all? Still, a very great idea for a mod, especially if the pages will be related to your phpBB forum and if you want that added sense of security for your members. :)

Please forgive my ignorance. I'm pretty new at this stuff. :oops:
The world is not yours to give; your heart is.
discipleao
Registered User
Posts: 63
Joined: Thu Jan 02, 2003 4:58 am

Post by discipleao »

What I do is this:

I have a "generic" .php file:

Code: Select all

<?php


define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'fetchposts.'.$phpEx);

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//

//
// Start output of page
//
$page_title = $lang['Articles'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);

$template->set_filenames(array(
        'body' => 'SOME_FILE_NAME.tpl')
);



//
// Generate the page
//
$template->pparse('body');

include($phpbb_root_path . 'includes/page_tail.'.$phpEx);

?>
That way my headers, footers, etc, are all consistent site-wide.

Like I said I have a section that is going to be for 'Articles' that is OUTSIDE the Forum, but will look & behave just like the forums.

ANYONE can view the articles, but in order to upload an article, you must login...come to my site and see....
carosel
Registered User
Posts: 24
Joined: Thu Sep 19, 2002 8:12 pm
Location: Matthews, NC
Contact:

Post by carosel »

Makes perfect sense. :)
Sounds almost like a portal. :)

Cool beans. :D
The world is not yours to give; your heart is.
Acecool
Registered User
Posts: 1013
Joined: Sat Jul 13, 2002 4:51 am
Location: Behind my computer
Contact:

Post by Acecool »

This is a RELEASED MOD

EDIT:

http://www.phpbb.com/phpBB/viewtopic.php?t=41672

Dont steal their work
Visit Acecoolco.com :: Image

If you plan on contacting me, please read this: Legal Terms & Conditions
discipleao
Registered User
Posts: 63
Joined: Thu Jan 02, 2003 4:58 am

Re: [Quasi-MOD] Block Guests from Viewing ANY Page

Post by discipleao »

discipleao wrote: Not really a MOD but I didn't know where else to put this.
And IF it is a MOD, then the credit goes to the author of the Hide All User Info MOD:

Code: Select all

darbyrob rob@wombatmedia.com (Rob Chojnacki)


The ONLY reason I am posting this was when I looked for the solution here, I found other users also looking, and very few answers. [/b]

LEARN TO READ
discipleao
Registered User
Posts: 63
Joined: Thu Jan 02, 2003 4:58 am

Post by discipleao »

...and for the at least third time...this is how I protect NON FORUM pges.
Some others were asking. I answered. This is how I do it.

Period.

If you want to protect "memberlist" & "usergroups" go right ahead.

NON forum.
Sound it out.

I did give credit where credit is due. I didn't STEAL anything...besides can you STEAL open-source??

ps RIF (Reading is FUN)
User avatar
adamch25
Registered User
Posts: 76
Joined: Sun Sep 08, 2002 4:07 pm
Location: Arizona
Contact:

Post by adamch25 »

Thanks for the MOD/Hack... works great. :)
Adam
realnerd
Registered User
Posts: 14
Joined: Mon Jan 12, 2004 6:51 am

Post by realnerd »

Hi I am trying to implement this code into my index.php so that all guests are forced to register. But I keep getting an error

Parse error: parse error in /home/babbleon/public_html/index.php on line 48

Here is the code I have in the index.php

Code: Select all

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//
//
// Block guests from viewing page - Redirect to login
//
if ( !$userdata['session_logged_in'] ) {
   $header_location = ( @preg_match("/Microsoft|WebSTAR|Xitami/", getenv("SERVER_SOFTWARE")) ) ? "Refresh: 0; URL=" : "Location: ";
   header($header_location . append_sid("login.".$phpEx."?redirect=login.".$phpEx, true));
   exit;
}
//
// End Block guests
//

FIND:
redirect=login.
FIND: is on line 48.

Thanks for any help possible
Tel
Registered User
Posts: 158
Joined: Mon Apr 28, 2003 5:33 pm
Location: UK

Post by Tel »

Or you can use:

Code: Select all

if( !$userdata['session_logged_in'] ) 
{ 
   header('Location: ' . append_sid("login.$phpEx?redirect=index.$phpEx", true)); 
} 
realnerd
Registered User
Posts: 14
Joined: Mon Jan 12, 2004 6:51 am

Post by realnerd »

Ugh, I still can't get the forum index to redirect to the login =[
realnerd
Registered User
Posts: 14
Joined: Mon Jan 12, 2004 6:51 am

Post by realnerd »

Hey I got it. Thank you for that piece of info worked like a charm!
Post Reply

Return to “[2.0.x] MODs in Development”

cron