I have a really nasty problem with sessions
and includes
in PHP. I have a page called index.php
in which I have a switch
function between the different pages:
<?php $p=(isset($_GET["p"])?$p=intval($_GET["p"]):$p=1); switch($p) {
case 1: $pagina = "login_and_registration.php";
break;
case 2: $pagina = "admin/registrazione.php";
break;
case 3: $pagina = "admin/login_test.php";
break;
case 4: $pagina = "logged_gym.php";
break;
case 5: $pagina = "logged_trainer.php";
break;
case 7: $pagina = "logout.php";
break;
case 8: $pagina = "admin/completa_profilo_trainer_sql.php";
break;
case 10: $pagina = "error.php";
break;
case 12: $pagina = "profilo_min.php";
break;
case 13: $pagina = "splash.php";
break;
default: $pagina = "index.php";
break;} ?>
Then down the code in the body of the file i have some includes:
<header class="container_12">
<?php include("login_errors.php")?>
<div id="logo_container" class="grid_4 push_4"></div></header >
And this one:
<section>
<?php include_once($pagina);?>
</section>
When I fill the form which is in this page, corresponding to page 1 in the switch function, i get this error on the login (where I start a new session with a name):
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /Applications/MAMP/htdocs/FitnessOptimize/index.php:63) in /Applications/MAMP/htdocs/FitnessOptimize/admin/login_test.php on line 73
In the index.php on line 63 i have the first include
that I just posted you. Any ideas on how to avoid this bug? Also my header ("Location: ")
; don't work i think for the same reason. Any help will be appreciated! Thanks to you all!