MyBB Community Forums

Full Version: how to force redirect non reg user to login
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How to redirect guest to login page only.

I already activated Force user to login, also am using Carbon Theme.

This is what it says:
I know i can edit this in language error lang.php but i dont want to edit none of this all i need is the login page for guest nothing else, redirect guest to login page if not logged in


You are either not logged in or do not have permission to view this page. This could be because one of the following reasons:
You are not logged in or registered. Please login and retry the desired action. Login | Need to register?
You do not have permission to access this page. Are you trying to access administrative pages or a resource that you shouldn't be? Check in the forum rules that you are allowed to perform this action.
Your account may have been disabled by an administrator, or it may be awaiting account activation.
You have accessed this page directly rather than using appropriate forms or links.

i need it now to just make user enter his username and password or click register, at the same page

I have try to edit home page to /member.php?action=login still not working
these string are in messages.lang.php file in your language folder (for english language is /inc/languages/english/)
key of these string is like this "error_nopermission_guest_1"
Mostafa.Shiraali, Hey there, i just want the login page to show not theses strings, i just want a way to hard code it, If anony go to login if login can view forum
modify template error_nopermission
I have updated my question
This could be easily done with some code lines in index.php

Simply check, whether there is a given "uid".
If not, do a PHP-redirect to "member.php?action=login".
if($mybb->user['uid'] == 0) { header('Location: https://.../member.php?action=login'); exit; }

Best you can put the PHP header mod in here:
29  if($mybb->user['uid'] != 0)
30  {
31      eval('$logoutlink = "'.$templates->get('index_logoutlink').'";');
32  }
-- else {
-- header('Location: https://.../member.php?action=login'); exit;
-- }

Good luck!

[ETS]
(2023-11-10, 01:27 AM)[ExiTuS] Wrote: [ -> ]This could be easily done with some code lines in index.php

Simply check, whether there is a given "uid".
If not, do a PHP-redirect to "member.php?action=login".
if($mybb->user['uid'] == 0) { header('Location: https://.../member.php?action=login'); exit; }

Best you can put the PHP header mod in here:
29  if($mybb->user['uid'] != 0)
30  {
31      eval('$logoutlink = "'.$templates->get('index_logoutlink').'";');
32  }
-- else {
-- header('Location: https://.../member.php?action=login'); exit;
-- }

Good luck!

[ETS]

Help me please this didnt work, my index page comes back Blank.

So i played abit with the code and it redirect to login even when am login

$logoutlink = '';
if($mybb->user['uid'] != 0)
{
eval('$logoutlink = "'.$templates->get('index_logoutlink').'";');
}
{
header ("Location: /member.php?action=login");
}

this code has user on login page even when hes login and guest user on forum how can i flip it i want guest user on login and reg user on forum
You missed else between the two conditions