How to Automatcially redirect to Forums after login

Ben
How to Automatcially redirect to Forums after login
Ben@49a5762e Tuesday 1st August 2023, 17:25:44

Here's how to add the code that will automatically redirect your users to the forums upon successful login after 3 seconds.

The file you want to edit is the auth.php in the main flatboard directory. It adds a java redirect that once the user has logged in, they are automatically redirected to the forum index page instead of needing to click the button. The button can still be used for those who may have javascript disabled.

Be sure to update the yoursite.com in the $redirect = ''https://... line

<?php
// ... Your existing code ...

if (HTMLForm::checkBot() && HTMLForm::check('trip', 0, 50) && User::login($_POST['trip']) && CSRF::check($token)) {
session_regenerate_id(true);
$domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false;
setcookie('flatboard_trip', $sessionTrip, time() + 3600 * 24, PATH_ROOT . DS, $domain, true, true);
$redirect = 'https://yoursite.com/flatboard/index.php/forum';

$out['content'] .= '<div class="alert alert-success">' . $lang['login_confirm'] . '</div>';
// JavaScript code to redirect after 3 seconds
$out['content'] .= '<script>
setTimeout(function() {
window.location.href = "' . $redirect . '";
}, 3000);
</script>';
}
else {
// ... Your existing code for login form ...
}

// ... Your existing code ...

Replies 2
Ben
Ben@49a5762e  Tuesday 1st August 2023, 21:50:24

Forgot one important line, in your auth.php directly in the code above, you will also want to add this line below which will redirect to the forums index page:

$redirect = 'https://yoursite.com/flatboard/index.php/forum'; // Replace 'https://yoursite.com/flatboard/index.php/forum' with the desired URL to your Forum or page

Ben
Ben@830e9da8  Sunday 20th August 2023, 02:59:19

Here's a modified version of the code that will take the user back to the page they were on when logging in. I like this a little better because say you want to reply to a forum post, it would take you back to a completely different page than the post you were on. This code should accomplish this and makes Flatboard even more intuitive. You can also change the redirect time to speed things up to like 2500 for 2.5 seconds.

Redirect to a static page code:

if (HTMLForm::checkBot() && HTMLForm::check('trip', 0, 50) && User::login($_POST['trip']) && CSRF::check($token)) {
session_regenerate_id(true);
$domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false;
setcookie('flatboard_trip', $sessionTrip, time() + 3600 * 24, PATH_ROOT . DS, $domain, true, true);
$redirect = 'https://yoursite.com/flatboard/index.php/forum';

$out['content'] .= '<div class="alert alert-success">' . $lang['login_confirm'] . '</div>';
// JavaScript code to redirect after 3 seconds
$out['content'] .= '<script>
setTimeout(function() {
window.location.href = "' . $redirect . '";
}, 3000);
</script>';
}


Edit the Flatboard auth.php and replace the code above with this code below:

[if (HTMLForm::checkBot() && HTMLForm::check('trip', 0, 50) && User::login($_POST['trip']) && CSRF::check($token)) {
session_regenerate_id(true);

// Get the previous URL and use it as the redirect URL
$referer = filter_var($_SERVER['HTTP_REFERER'], FILTER_VALIDATE_URL);
$redirect = ($referer !== false) ? $referer : 'index.php'; // Redirect to index.php if referer is not valid

// Update the success message
$out['content'] .= '<div class="alert alert-success">' . $lang['login_confirm'] . '</div>';

// JavaScript code to redirect after 3 seconds
$out['content'] .= '<script>
setTimeout(function() {
window.location.href = "' . $redirect . '";
}, 3000);
</script>';
}

Last modified by Ben@830e9da8 on Sunday 20th August 2023, 03:23:00

Suggested Topics
started
69K 0
5.4K 0
Fred
10.5K 11
Want to read more? Browse all categories or view latest topics.