This php function currently redirects the user to another page if they aren’t logged in
if(!isset($_SESSION['SESS_USER_ID']) || (trim($_SESSION['SESS_USER_ID']) == '')){
header("location: login_failed.html");
exit();
}
How can I change the function so that instead of redirecting the user it does the following:
- Triggers the javascript function:
loginFailed(); - Prevents specific iframes which are preloaded from launching (these require a user to be logged in, and are currently opening as empty iframes if they’re not logged in). I’ve included the script for this below. Alternatively, preventing iframes from launching which have a specific class or data-fancybox-type, or those which require
!isset($_SESSION['SESS_USER_ID']).
The functions which I want to trigger/prevent
function loginFailed() {
$().toastmessage('showToast', {
text: 'Log In Failed<br/><br/>Please check your username and password',
sticky: false,
position: 'top-center',
type: 'message',
closeText: '',
close: function () { console.log("toast is closed ...") }
});
}
$(function () {
$(".fancybox").fancybox({
preload: true,
});
$(".fancybox").eq(0).trigger('click');
});
I’ve tried:
echo "<script>loginFailed();</script>";
echo "<script type="text/javascript">loginFailed();</script>";
echo "<script type="text/javascript">loginFailed;</script>";
I combined @hellohellosharp’s suggestion with a solution which was given to me by @willoller for another problem and figured it out 🙂
Add this to the php:
Add this to the javascript:
I’m also using this to change the menu options based on whether or not a user’s logged in.
Just a reminder – this uses ISSET to determine what javascript should show, but it only changes the user’s experience and doesn’t provide any security.