News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

How do you redirect a user to a previous page using SSI?

Started by revgreed, June 17, 2023, 06:34:01 PM

Previous topic - Next topic

revgreed

I am making a website in which I am restricting content to logged in users with SSI.

I'm using:  SMF 2.1.4, PHP 8.1.2

My pages are coded from the guidance using this wiki:  https://wiki.simplemachines.org/smf/How_to_use_the_SMF_user_system_outside_of_SMF

Therefore, my pages look like this:

<?php
require("/var/www/html/community/SSI.php");
?>
<?php
               
if ($context['user']['is_logged'])
               {
                       echo
'
                               <div>

<--------------------------HTML-------------------------->

</div>'
;
}
else
{
redirectexit('https://mywebsite.com/event/login.php');
}
?>
</body>
</html>

And my LOGIN.PHP is based on this post: https://www.simplemachines.org/community/index.php?topic=577398.msg4086427#msg4086427

<?php
include '/var/www/html/community/SSI.php';
?>
<------------------HTML---------------------------->
            <p class="title">
                <?php ssi_welcome(); ?>
            </p>
<-------------------HTML---------------------------->
                <?php
               
if ($context['user']['is_guest']) {
                   
$_SESSION['login_url'] = $_SERVER['HTTP_REFERER']; // Record the previous page URL
                   
ssi_login($_SESSION['login_url']); // Pass the URL as an argument to ssi_login()
               
} else {
                   
$_SESSION['logout_url'] = 'https://mywebsite.com';
                   
ssi_logout();
               }
               
?>

<-------------------------HTML------------------------------->

If the user is not logged in, then the script has no issue referring the user to the LOGIN.PHP page.  The problem I'm running into is that regardless of which page the user enters my website, and they are referred to LOGIN.PHP - after they enter the appropriate credentials, the user is then sent to the home screen of the forum as opposed to going back to the previous page they entered the website.

Can someone provide some guidance pertaining to my code on how to refer the user back to the previous page, then being able to navigate the rest of the website after logging in?

Thank you for your time.

Doug Heffernan

Can you try to do the redirection with with header() instead and using the HTTP_REFERER?

Advertisement: