Simple Machines Community Forum

Customizing SMF => Bridges and Integrations => Topic started by: revgreed on March 18, 2017, 01:54:20 AM

Title: Require SMF login
Post by: revgreed 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!
Title: Re: Require SMF login
Post by: Arantor 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.
Title: Re: Require SMF login
Post by: Kindred on March 18, 2017, 07:48:09 AM
Do your existing pages share a header or other common file?
Title: Re: Require SMF login
Post by: revgreed 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.

Quote from: Kindred on March 18, 2017, 07:48:09 AM
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:


<?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:


<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:


<?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.
Title: Re: Require SMF login
Post by: Kindred on March 19, 2017, 08:33:38 AM
either include the  HTML within the if/then/else


<?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
Title: Re: Require SMF login
Post by: Arantor on March 19, 2017, 06:35:18 PM
If you want to force a login, just:


<?php
require("/home1/mysite/public_html/mysite/forum/SSI.php");
is_not_guest();
?>



at the top before everything else.
Title: Re: Require SMF login
Post by: revgreed on March 19, 2017, 10:36:06 PM
Quote from: Arantor on March 19, 2017, 06:35:18 PM
If you want to force a login, just:


<?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.