Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

Redirect a non-logged in Member to a 'Login' page?

Asked Modified Viewed 3,378 times
N
Newtype
N
  • Junior Member, joined since
  • Contributed 16 posts on the community forums.
  • Started 6 threads in the forums
  • Started this discussions
asked
Junior Member

I've set the time out for member sessions to 30 minutes. However, once logged out they can still end up at a page with no content on it. I need any non-member or non-logged in member to be redirected to the login page.

I've tried this at the top of a page to test:

if (!iMEMBER) { redirect(BASEDIR."login.php"wink; }

but the redirection is not occurring. My gut tells me that I need some time of global session call in the line prior but I am not sure what I need there...
0 replies

8 posts

N
Newtype
N
  • Junior Member, joined since
  • Contributed 16 posts on the community forums.
  • Started 6 threads in the forums
  • Started this discussions
answered
Junior Member

I think I understand how that preg_match works now. It's a conditional statement that you can set as a positive or negative correct?
0 replies
F
Falk
F
Falk 146
Need help?, Having trouble?
• View our Documentation for Guides, Standards and Functions
• Name and Organize your Topics and Content correctly in the corresponding Forums for best support results
• Attaching Log Files and Screenshots when reporting issues will help
• Provide with an URL to live example if one exists
• Please read the How to Report an Error post
• Please read and comply with the Code of Conduct

(¯·._.·(¯°·._.·°º*[ Project Manager ]*º°·._.·°¯)·._.·¯)
  • Super Admin, joined since
  • Contributed 6,201 posts on the community forums.
  • Started 639 threads in the forums
  • Answered 12 questions
answered
Super Admin

Could probably just nest it,

if (!preg_match('/register.php/i', $_SERVER['PHP_SELF'])) {
if (!preg_match('/login.php/i', $_SERVER['PHP_SELF'])) {
if (!iMEMBER) { redirect(BASEDIR."login.php"); }
}
}
0 replies
N
Newtype
N
  • Junior Member, joined since
  • Contributed 16 posts on the community forums.
  • Started 6 threads in the forums
  • Started this discussions
answered
Junior Member

Bam! That did the trick. I was looking at other pages and researched the 'preg_match' function but couldn't get it to work.

Thanks Domi, you are always on point!

Merged on Feb 17 2014 at 23:37:01:
Everything's working fine until someone tries to register. The redirect is preventing them from going to registration.php. Any way to add an exception? That preg_match is confusing in the documentation at php.net...
Edited by Newtype on 18-02-2014 06:37,
0 replies
F
Falk
F
Falk 146
Need help?, Having trouble?
• View our Documentation for Guides, Standards and Functions
• Name and Organize your Topics and Content correctly in the corresponding Forums for best support results
• Attaching Log Files and Screenshots when reporting issues will help
• Provide with an URL to live example if one exists
• Please read the How to Report an Error post
• Please read and comply with the Code of Conduct

(¯·._.·(¯°·._.·°º*[ Project Manager ]*º°·._.·°¯)·._.·¯)
  • Super Admin, joined since
  • Contributed 6,201 posts on the community forums.
  • Started 639 threads in the forums
  • Answered 12 questions
answered
Super Admin

hehe, yeah sorry about that.

if (!preg_match('/login.php/i', $_SERVER['PHP_SELF'])) { 
if (!iMEMBER) { redirect(BASEDIR."login.php"); }
}

You could put em on the same row too, but I just give the basics.
0 replies
N
Newtype
N
  • Junior Member, joined since
  • Contributed 16 posts on the community forums.
  • Started 6 threads in the forums
  • Started this discussions
answered
Junior Member

Did that. Is there a particular place in the themes.php file? I put it on top and my browser failed with a redirect loop...

*facepalms
0 replies
F
Falk
F
Falk 146
Need help?, Having trouble?
• View our Documentation for Guides, Standards and Functions
• Name and Organize your Topics and Content correctly in the corresponding Forums for best support results
• Attaching Log Files and Screenshots when reporting issues will help
• Provide with an URL to live example if one exists
• Please read the How to Report an Error post
• Please read and comply with the Code of Conduct

(¯·._.·(¯°·._.·°º*[ Project Manager ]*º°·._.·°¯)·._.·¯)
  • Super Admin, joined since
  • Contributed 6,201 posts on the community forums.
  • Started 639 threads in the forums
  • Answered 12 questions
answered
Super Admin

If you want it global you need to insert this in your current theme´s theme.php.
If you do not do that, you need to mod each and every section of your site you want to restrict.
0 replies
N
Newtype
N
  • Junior Member, joined since
  • Contributed 16 posts on the community forums.
  • Started 6 threads in the forums
  • Started this discussions
answered
Junior Member

I believe I am doing what you are instructing. Sample page from my setup:

<?php require_once "maincore.php"; require_once THEMES."templates/header.php";
if (!iMEMBER) { redirect(BASEDIR."login.php"wink; }
$query.....

Is there a different spot? Before the Themes inclusion?

I test this by logging out and pasting in the path to, for example, the Forums page. The page still displays with nothing but Public viewable panels. Even a refresh does not trigger the redirect.
0 replies
F
Falk
F
Falk 146
Need help?, Having trouble?
• View our Documentation for Guides, Standards and Functions
• Name and Organize your Topics and Content correctly in the corresponding Forums for best support results
• Attaching Log Files and Screenshots when reporting issues will help
• Provide with an URL to live example if one exists
• Please read the How to Report an Error post
• Please read and comply with the Code of Conduct

(¯·._.·(¯°·._.·°º*[ Project Manager ]*º°·._.·°¯)·._.·¯)
  • Super Admin, joined since
  • Contributed 6,201 posts on the community forums.
  • Started 639 threads in the forums
  • Answered 12 questions
answered
Super Admin

You need to insert it below maincore.php inclusions.
0 replies

Category Forum

User Administration - 8

Labels

None yet

Statistics

  • Views 0 views
  • Posts 8 posts
  • Votes 0 votes
  • Topic users 2 members

2 participants

F
F
Falk 146
Need help?, Having trouble?
• View our Documentation for Guides, Standards and Functions
• Name and Organize your Topics and Content correctly in the corresponding Forums for best support results
• Attaching Log Files and Screenshots when reporting issues will help
• Provide with an URL to live example if one exists
• Please read the How to Report an Error post
• Please read and comply with the Code of Conduct

(¯·._.·(¯°·._.·°º*[ Project Manager ]*º°·._.·°¯)·._.·¯)
  • Super Admin, joined since
  • Contributed 6,201 posts on the community forums.
  • Started 639 threads in the forums
  • Answered 12 questions
N
N
  • Junior Member, joined since
  • Contributed 16 posts on the community forums.
  • Started 6 threads in the forums
  • Started this discussions

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet