Jump to content

How do I put an IF statment into a SWITCH CASE Function?


Dethman

Recommended Posts

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!

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.