[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:

<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>

session2.php:

<?php
session_start();
$_SESSION['var1']='Javadomain.in';
header ("Location: session1.php");
?>

Output:
without session issue

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
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>

session2.php:

<?php
session_start();
$_SESSION['var1']='Javadomain.in';
header ("Location: session1.php");
?>

Now output is,
without session

PHP Recommended Books:

542 total views, 4 views today

Leave a Reply

Your email address will not be published. Required fields are marked *