Advertisement:

Author Topic: Require SMF login  (Read 3562 times)

Offline revgreed

  • Charter Member
  • Semi-Newbie
  • *
  • Posts: 77
  • Gender: Male
    • sinning.org
Require SMF login
« on: March 18, 2017, 01:54:20 AM »
Hello,

I am wanting to require a SMF login in order to access any part of my website except http://www.mysite.org/index.htm.  More Specific, I want to require that the login takes place at my custom .php page which I used SSI.

For example:  http://www.mysite.org/login.php

My site already exists and it has hundreds of directories, pages, etc, so it's not very feasible to edit and add a 'require SSI.php' to every page. 

That being said - is this easiest accomplished with a .htaccess file and to require every user has to pass through http://www.mysite.org/login.php in order to access all other pages of the site?  If so, can you help me with the syntax for the .htaccess file?

I hope I'm making sense, and I sincerely appreciate all your help!

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,035
    • Arantor on GitHub
Re: Require SMF login
« Reply #1 on: March 18, 2017, 04:38:18 AM »
Not really, it is best to actually add it to your pages, as unfortunate as that seems.
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 55,101
  • Gender: Male
    • Kindred-999 on GitHub
Re: Require SMF login
« Reply #2 on: March 18, 2017, 07:48:09 AM »
Do your existing pages share a header or other common file?
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline revgreed

  • Charter Member
  • Semi-Newbie
  • *
  • Posts: 77
  • Gender: Male
    • sinning.org
Re: Require SMF login
« Reply #3 on: March 19, 2017, 05:16:08 AM »
Arantor & Kindred,

I hope you're both doing well and I again thank you for your assistance here.

Do your existing pages share a header or other common file?

Sometimes.  Most are random 1995-era-looking HTML files.  But after spending all day thinking about it - I think I want to integrate SMF throughout, so I'll undergo the tedious task of editing the files.  So, I need help with this one file, then I should be able to get the rest:

I figured this out by reading the online manual wiki:

Code: [Select]
<?php
require("path.to./forum/SSI.php");
if (
$context['user']['is_guest'])
   {
      
ssi_login();
   }
else
   {
      
ssi_welcome();
   }

?>

And here is one of pre-existing HTML files:

Code: [Select]
<HTML>
<HEAD>
<TITLE>mysite.org - welcome</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000000"
VLINK="#000000">

<P><TABLE BORDER="0" WIDTH="100%" HEIGHT="100%">
   <TR>
      <TD WIDTH="800">
         <P ALIGN=CENTER><CENTER><TABLE BORDER="0" WIDTH="600">

            <TR>
               <TD WIDTH="509" HEIGHT="67">
                  <P>&nbsp;</P>

                  <P><a href="http://www.mysite.org/warning.htm"><img src="http://www.mysite.org/images/mysite.jpg" border="0">
                  </P>

                  </TD></TR>
         </TABLE></CENTER>
      </TD></TR>
</TABLE></P>
</BODY>
</HTML>

So, I simply added the two pieces of code together and changed the file extension to *.php as so:

Code: [Select]
<?php
require("/home1/mysite/public_html/mysite/forum/SSI.php");
if (
$context['user']['is_guest'])
   {
      
ssi_login();
   }
else
   {
      
ssi_welcome();
   }

?>

<HTML>
<HEAD>
<TITLE>mysite.org - welcome</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000000"
VLINK="#000000">

<P><TABLE BORDER="0" WIDTH="100%" HEIGHT="100%">
   <TR>
      <TD WIDTH="800">
         <P ALIGN=CENTER><CENTER><TABLE BORDER="0" WIDTH="600">

            <TR>
               <TD WIDTH="509" HEIGHT="67">
                  <P>&nbsp;</P>

                  <P><a href="http://www.mysite.org/warning.htm"><img src="http://www.mysite.org/images/mysite.jpg" border="0">
                  </P>

                  </TD></TR>
         </TABLE></CENTER>
      </TD></TR>
</TABLE></P>
</BODY>
</HTML>

However, in the case just above - the output displays BOTH the SSI login fields and the HTML display.

What I am trying to accomplish is that if the user is a GUEST then the GUEST sees nothing but the login or registering screen.

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 55,101
  • Gender: Male
    • Kindred-999 on GitHub
Re: Require SMF login
« Reply #4 on: March 19, 2017, 08:33:38 AM »
either include the  HTML within the if/then/else

Code: [Select]
<?php
require("/home1/mysite/public_html/mysite/forum/SSI.php");
if (
$context['user']['is_guest'])
   {
      
ssi_login();
   }
else
   {
      
ssi_welcome();
?>

<HTML>
<HEAD>
<TITLE>mysite.org - welcome</TITLE>
</HEAD>
<?php   ?>

?>


or include a die statement
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,035
    • Arantor on GitHub
Re: Require SMF login
« Reply #5 on: March 19, 2017, 06:35:18 PM »
If you want to force a login, just:

Code: [Select]
<?php
require("/home1/mysite/public_html/mysite/forum/SSI.php");
is_not_guest();
?>


at the top before everything else.
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline revgreed

  • Charter Member
  • Semi-Newbie
  • *
  • Posts: 77
  • Gender: Male
    • sinning.org
Re: Require SMF login
« Reply #6 on: March 19, 2017, 10:36:06 PM »
If you want to force a login, just:

Code: [Select]
<?php
require("/home1/mysite/public_html/mysite/forum/SSI.php");
is_not_guest();
?>


at the top before everything else.

Perfect.  That does the job because I can simply redirect the login regardless where the user enters the site.  Thanks again.