Conditional session and redirect

[b]code[/b]

<?php session_start();?>
<!doctype html>
<html>
 
  <head>
    <meta charset="UTF-8">
    <title>if-sess_re</title>
</head>
<body>

<?php 
if (isset($_SESSION['$mySession']))
{header("Location: http://www.isset.com/");
}
else
{header("Location: http://www.noset.com/");}
?>
</body>
</html>


[b]result[/b]

[B]Warning[/B]: Cannot modify header information - 
headers already sent by (output started at if-session_redirect.php:11) 
in if-session_redirect.php on line 13

The code above in http://dot.kr/x-test/if-session_redirect.php needs <?php session_start();?> because it should know session is already set or not yet.
But It should not used in header.

Then how can I make redirection in session condition?

[FPHP]header[/FPHP] will only work if no previous output is generated before the header() statement.

output can include empty blank lines and leading/trailing blank spaces on a line.

if you put

 
<?php 
if (isset($_SESSION['$mySession']))
{header("Location: http://www.isset.com/");
}
else
{header("Location: http://www.noset.com/");}
?>
 

directly below session_start(), your redirects should work.

put session_start() as the very first line in your php file.