doubledee Posted March 24, 2012 Share Posted March 24, 2012 When a User logs out, I redirect them like this... if (isset($_SESSION['returnToPage']) && ($_SESSION['returnToPage'] != 'members/my_account.php')){ $returnToPage = $_SESSION['returnToPage']; }else{ $returnToPage = "/index.php"; } In English I am saying, "If you were just on the My Account page, go to the Home Page because the returnToPage could have been something else that would confuse you if you went back there?!" Now I want to do the same thing for 6 other pages related to My Account. Is there an efficient way to do that versus a really ugly IF-THEN-ELSE?? Thanks, Debbie Quote Link to comment https://forums.phpfreaks.com/topic/259600-better-way-to-say-dont-go-to-these-pages/ Share on other sites More sharing options...
l0gic Posted March 24, 2012 Share Posted March 24, 2012 So, why not just use.. if($_SESSION['loggedOut']) == true) { $returnToPage = "/index.php";} }else { $returnToPage = $_SESSION['returnToPage']; } ..on each page? Quote Link to comment https://forums.phpfreaks.com/topic/259600-better-way-to-say-dont-go-to-these-pages/#findComment-1330662 Share on other sites More sharing options...
doubledee Posted March 24, 2012 Author Share Posted March 24, 2012 So, why not just use.. if($_SESSION['loggedOut']) == true) { $returnToPage = "/index.php";} }else { $returnToPage = $_SESSION['returnToPage']; } ..on each page? I could, but I'm thinking it might be more complicated since on each page it is possible (?) to have different $returnToPages based on the logic of the page. (At this late stage I don't wanna muck with that variable.) I figured it would be easier to say, "If you are on any of these 6 pages, then ignore the $returnToPage and go to the index.php page." Debbie Quote Link to comment https://forums.phpfreaks.com/topic/259600-better-way-to-say-dont-go-to-these-pages/#findComment-1330667 Share on other sites More sharing options...
darkfreaks Posted March 24, 2012 Share Posted March 24, 2012 why not use a switch for $_SESSION['returnToPage''] then you could use the case to pass your arguments in. switch($_SESSION['ReturnToPage']){ case($_SESSION['ReturnToPage']=='allowedfile1'): $returntopage=$_SESSION['ReturnToPage']; //do the same for all pages you want allowed. break; } echo $returntopage; Quote Link to comment https://forums.phpfreaks.com/topic/259600-better-way-to-say-dont-go-to-these-pages/#findComment-1330671 Share on other sites More sharing options...
AyKay47 Posted March 24, 2012 Share Posted March 24, 2012 Does $_SESSION['returnToPage'] simply hold the http_referer? A switch is the way to go for this I believe, to compare multiple values against the session value. darkfreaks was close, however the switch syntax is a little off: $returnToPage = null; switch($_SESSION['returnToPage']) { case 'members/my_account.php': $returnToPage = '/index.php'; break; default: $returnToPage = $_SESSION['returnToPage']; break; } You will add new cases for each referer that you do not want to set $returnToPage to the session value. The default condition will trigger if the session value does not equal any case values. You can (should?) add the switch into an if statement checking for the session being set first. Quote Link to comment https://forums.phpfreaks.com/topic/259600-better-way-to-say-dont-go-to-these-pages/#findComment-1330737 Share on other sites More sharing options...
doubledee Posted March 24, 2012 Author Share Posted March 24, 2012 Does $_SESSION['returnToPage'] simply hold the http_referer? A switch is the way to go for this I believe, to compare multiple values against the session value. darkfreaks was close, however the switch syntax is a little off: $returnToPage = null; switch($_SESSION['returnToPage']) { case 'members/my_account.php': $returnToPage = '/index.php'; break; default: $returnToPage = $_SESSION['returnToPage']; break; } You will add new cases for each referer that you do not want to set $returnToPage to the session value. The default condition will trigger if the session value does not equal any case values. You can (should?) add the switch into an if statement checking for the session being set first. I need to re-think how I'm doing this, but your suggestion has merits! Thanks, Debbie Quote Link to comment https://forums.phpfreaks.com/topic/259600-better-way-to-say-dont-go-to-these-pages/#findComment-1330746 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.