Closing my phpBB's access

Discuss phpBB 3.0.x in general.
Forum rules
Please post any phpBB 3.1.x related topics in the phpBB 3.1.x discussion forum.
User avatar
EY
Supporter
Supporter
Posts: 204
Joined: 05 Nov 2006, 23:13
Real name: Elias
Location: Montreal

Closing my phpBB's access

Postby EY » 02 Aug 2012, 06:20

Hello everyone!

I am looking for the best way on closing down access to all guests visiting my website.
I do not mean not letting them see the forums. I mean hiding the whole board from guests and redirect them to the log in page when ever they visit any page.

What is the best way of doing this?


Thanks in advance.
Never Say Never!

User avatar
tumba25
Past Contributor
Past Contributor
Posts: 1058
Joined: 24 Oct 2007, 13:10
Real name: Jari Kanerva
Location: Kokkola, Finland.

Re: Closing my phpBB's access

Postby tumba25 » 02 Aug 2012, 22:01

ATM I can't think of any easier way than to add a check to function session_begin() in session.php. Something like this.

Open includes/session.php
FIND

Code: Select all

$this->data['is_registered'] = ($this->data['user_id'] != ANONYMOUS && ($this->data['user_type'] == USER_NORMAL || $this->data['user_type'] == USER_FOUNDER)) ? true : false;

BEFORE ADD

Code: Select all

if ($this->data['user_id'] == ANONYMOUS && strpos($this->page['page'], "ucp.$phpEx") === false)
{
   redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login'));
}

Almost not tested at all. That gives only access to ucp.php for not logged in users. Allowing them to login or register. If you disable registration they will of course not have access to that page either.

User avatar
EY
Supporter
Supporter
Posts: 204
Joined: 05 Nov 2006, 23:13
Real name: Elias
Location: Montreal

Re: Closing my phpBB's access

Postby EY » 03 Aug 2012, 04:36

I tested this and it works!

Instead of using the UCP page, how can i use my own page which would be the index.php of my website, a login screen for unregistered users?

Thanks for the help.
Never Say Never!

User avatar
tumba25
Past Contributor
Past Contributor
Posts: 1058
Joined: 24 Oct 2007, 13:10
Real name: Jari Kanerva
Location: Kokkola, Finland.

Re: Closing my phpBB's access

Postby tumba25 » 04 Aug 2012, 04:04

Your website being the forum? Or some external page? I assume the website is the forum.

Open includes/session.php
Replace the code you added above with this

Code: Select all

if ($this->data['user_id'] == ANONYMOUS && strpos($this->page['page'], "index.$phpEx") === false && strpos($this->page['page'], "ucp.$phpEx") === false)
{
   redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
}


Open index.php
FIND

Code: Select all

$user->setup('viewforum');

ADD AFTER

Code: Select all

if ($user->data['user_id'] == ANONYMOUS)
{
   $user->add_lang('ucp');

   $s_hidden_fields = array(
      'sid'      => $user->session_id,
      'redirect'   => "{$phpbb_root_path}index.$phpEx"
   );

   $template->set_filenames(array(
      'body' => 'login_body.html'
   ));

   $s_hidden_fields = build_hidden_fields($s_hidden_fields);
   $template->assign_vars(array(
      'USERNAME'            => '',
      'USERNAME_CREDENTIAL'   => 'username',
      'PASSWORD_CREDENTIAL'   => 'password',

      'S_AUTOLOGIN_ENABLED'   => ($config['allow_autologin']) ? true : false,
      'S_DISPLAY_FULL_LOGIN'   => true,
      'S_HIDDEN_FIELDS'      => $s_hidden_fields,
      'S_LOGIN_ACTION'      => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login'),
      'S_LOGIN_REDIRECT'      => build_hidden_fields(array('redirect' => build_url())),

      'U_RESEND_ACTIVATION'   => ($config['require_activation'] == USER_ACTIVATION_SELF && $config['email_enable']) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=resend_act') : '',
      'U_SEND_PASSWORD'   => ($config['email_enable']) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=sendpassword') : '',
   ));

   // Output page
   page_header($user->lang['LOGIN']);

   page_footer();
}

Unless you plan to replace the whole index.php with ucp.php you need to have it accessible for guests. You could of course with some more edits incluce ucp.php in index.php when the user is not logged in. So guests never can access ucp.php. But I'm to tired to think about that now, need to get some sleep.

User avatar
EY
Supporter
Supporter
Posts: 204
Joined: 05 Nov 2006, 23:13
Real name: Elias
Location: Montreal

Re: Closing my phpBB's access

Postby EY » 09 Aug 2012, 03:31

Here is what i am looking to do:

If a user isn't logged in, i want them redirected to an external page that i have created for my forum that would ask them to log in.
Never Say Never!

User avatar
EY
Supporter
Supporter
Posts: 204
Joined: 05 Nov 2006, 23:13
Real name: Elias
Location: Montreal

Re: Closing my phpBB's access

Postby EY » 09 Aug 2012, 18:05

I could also modify the ucp.php file to fit my login needs and use it.

Any idea what file i need to edit to modify the ucp.php login?
Never Say Never!

User avatar
tumba25
Past Contributor
Past Contributor
Posts: 1058
Joined: 24 Oct 2007, 13:10
Real name: Jari Kanerva
Location: Kokkola, Finland.

Re: Closing my phpBB's access

Postby tumba25 » 09 Aug 2012, 20:28

EY wrote:Any idea what file i need to edit to modify the ucp.php login?

ucp.php? That would depend on what you want to modify. The login_box() function is in functions.php.

User avatar
EY
Supporter
Supporter
Posts: 204
Joined: 05 Nov 2006, 23:13
Real name: Elias
Location: Montreal

Re: Closing my phpBB's access

Postby EY » 10 Aug 2012, 03:31

I got it all working.

I used the first code you gave me and i then modified my login_body.html to remove everything i needed.

Thank you very much for your help!
Never Say Never!

User avatar
tumba25
Past Contributor
Past Contributor
Posts: 1058
Joined: 24 Oct 2007, 13:10
Real name: Jari Kanerva
Location: Kokkola, Finland.

Re: Closing my phpBB's access

Postby tumba25 » 10 Aug 2012, 12:47

You're welcome.


Return to “phpBB 3.0.x "Olympus" discussion”

Who is online

Users browsing this forum: CommonCrawl [Bot] and 4 guests