[Solved] Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at
Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at
session_start() should be used first line in the php code and php code should exist even above the html tag.
session1.php:
[php]
<html>
<?php
session_start();
$check = 0;
if(isset($_SESSION[‘var1’])){
$check =1;
}
?>
<head>
</head>
<body>
<?php
if($check==1){
?>
With Session
<?php
}else{
?>
Without Session.
<a href="session2.php">Click here to initate the session</a>
<?php
}
?>
</body>
</html>
[/php]
session2.php:
[php]
<?php
session_start();
$_SESSION[‘var1′]=’Javadomain.in’;
header ("Location: session1.php");
?>
[/php]
As discussed already, if you move the php part to before the html tag, then we will not be getting the issue.
session1.php:
[php]
<?php
session_start();
$check = 0;
if(isset($_SESSION[‘var1’])){
$check =1;
}
?>
<html>
<head>
</head>
<body>
<?php
if($check==1){
?>
With Session
<?php
}else{
?>
Without Session.
<a href="session2.php">Click here to initate the session</a>
<?php
}
?>
</body>
</html>
[/php]
session2.php:
[php]
<?php
session_start();
$_SESSION[‘var1′]=’Javadomain.in’;
header ("Location: session1.php");
?>
[/php]
PHP Recommended Books: