Dethman Posted August 8, 2008 Share Posted August 8, 2008 Ok basically I need this How would I do something like this? <?php case "Base" and $_SESSION['userid']==$player['userid']: include("lib_html/base.php"); but if case "base" and $_SESSION['userid'] !=$player['userid'] header("LOCATION: index.php?strErr=You are not logged in please Login before going any further"); ?> Any one able to help BTW here is the case's I already have... <?php $page=$_GET['page']; function main(){ if(isset($_SESSION['userid'])){ include("lib_html/lair.php"); } else{ include("lib_html/main.php"); } } switch($page){ case "Login": include("lib_html/login.php"); break; case "SignUp": include("lib_html/SignUp.php"); break; case "Help": include("lib_html/help.php"); break; case "Report": include("lib_html/report.php"); break; case "TopFactions": include("lib_html/topFactions.php"); break; case "Events": include("lib_html/events.php"); break; case "Lair": include("lib_html/lair.php"); break; case "BattleField": include("lib_html/battlefield.php"); break; case "Armory": include("lib_html/Armory.php"); break; case "Train": include("lib_html/Train.php"); break; case "BattleLogs": include("lib_html/BattleLogs.php"); break; case "Diety": include("lib_html/Diety.php"); break; case "Tech": include("lib_html/Tech.php"); break; case "Market": include("lib_html/Market.php"); break; case "Logout": include("lib_html/logout.php"); break; default: main(); } ?> Thanx for any help on this, Brian Flores CEO, NimbusGames,llc! Link to comment https://forums.phpfreaks.com/topic/118723-how-do-i-put-an-if-statment-into-a-switch-case-function/ Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 Did you even try to just code it in? o-O It should work just fine. Link to comment https://forums.phpfreaks.com/topic/118723-how-do-i-put-an-if-statment-into-a-switch-case-function/#findComment-611260 Share on other sites More sharing options...
nrg_alpha Posted August 8, 2008 Share Posted August 8, 2008 As Darkwater mentioned, it looks fine.. but I did find that you had an extra curly brace in your if statment: if(isset($_SESSION['userid'])){ include("lib_html/lair.php"); } else{ include("lib_html/main.php"); } } should be: if(isset($_SESSION['userid'])){ include("lib_html/lair.php"); } else { include("lib_html/main.php"); } You need to delete that last brace. Cheers, NRG Link to comment https://forums.phpfreaks.com/topic/118723-how-do-i-put-an-if-statment-into-a-switch-case-function/#findComment-611262 Share on other sites More sharing options...
Dethman Posted August 8, 2008 Author Share Posted August 8, 2008 Guy I need an If Statment between the cases like this: <?php case "Lair": if(isset($_SESSION['id']){ include("lib_html/lair.php"); }else{ header("LOCATION: index.php?strErr=You are not logged in!"); } break; ?> will that work? Link to comment https://forums.phpfreaks.com/topic/118723-how-do-i-put-an-if-statment-into-a-switch-case-function/#findComment-611271 Share on other sites More sharing options...
nrg_alpha Posted August 8, 2008 Share Posted August 8, 2008 Guy I need an If Statment between the cases like this: <?php case "Lair": if(isset($_SESSION['id']){ include("lib_html/lair.php"); }else{ header("LOCATION: index.php?strErr=You are not logged in!"); } break; ?> will that work? I don't know.. have you tried it? I have never seen nor tried something like that before.. but one way to find out is to try it and see.. if it does not give you the results you seek, then I suppose it doesn't work. On the surface, it looks like it would work. Try it out. Cheers, NRG Link to comment https://forums.phpfreaks.com/topic/118723-how-do-i-put-an-if-statment-into-a-switch-case-function/#findComment-611274 Share on other sites More sharing options...
deadlyp99 Posted August 8, 2008 Share Posted August 8, 2008 To make the code more readable use a function. case "lawls": runymyfunction(); Link to comment https://forums.phpfreaks.com/topic/118723-how-do-i-put-an-if-statment-into-a-switch-case-function/#findComment-611278 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.