Page 1 of 2

[Quasi-MOD] Block Guests from Viewing ANY Page

Posted: Thu Jan 09, 2003 7:27 pm
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.

Posted: Mon Jan 20, 2003 12:38 am
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.

Posted: Mon Jan 20, 2003 5:48 am
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? :)

Posted: Mon Jan 20, 2003 6:31 am
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.

Posted: Tue Jan 21, 2003 3:29 am
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:

Posted: Tue Jan 21, 2003 4:45 am
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....

Posted: Tue Jan 21, 2003 5:33 pm
by carosel
Makes perfect sense. :)
Sounds almost like a portal. :)

Cool beans. :D

Posted: Tue Jan 21, 2003 5:52 pm
by Acecool
This is a RELEASED MOD

EDIT:

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

Dont steal their work

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

Posted: Tue Jan 21, 2003 8:11 pm
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

Posted: Tue Jan 21, 2003 8:15 pm
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)

Posted: Wed Jan 07, 2004 5:24 am
by adamch25
Thanks for the MOD/Hack... works great. :)

Posted: Mon Jan 12, 2004 11:28 pm
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

Posted: Mon Jan 12, 2004 11:51 pm
by Tel
Or you can use:

Code: Select all

if( !$userdata['session_logged_in'] ) 
{ 
   header('Location: ' . append_sid("login.$phpEx?redirect=index.$phpEx", true)); 
} 

Posted: Tue Jan 13, 2004 12:12 am
by realnerd
Ugh, I still can't get the forum index to redirect to the login =[

Posted: Tue Jan 13, 2004 12:22 am
by realnerd
Hey I got it. Thank you for that piece of info worked like a charm!