<?php
include 'ProcessDAO.php';
$dest="";
if(isset($_POST['login'])){
    session_start(); // i get an error in this line !!
    $_SESSION['status']='online';
    $_SESSION['breadcrumb']='home';
    $pro = new ProcessDAO();
    $dest = $pro->LogIn($_POST['username'],$_POST['password']);
}else{
    session_start();
    $dest ="Location: ../index.php";
    session_destroy();
}
header($dest);
?>

guyss can you help me out because in my Login.PHP file when i login i always get this error .

** Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\IPMS\process\ProcessDAO.php:1) in C:\xampp\htdocs\IPMS\process\login.php on line 5**

Member Avatar for LastMitch

@syria718

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\IPMS\process\ProcessDAO.php:1) in C:\xampp\htdocs\IPMS\process\login.php on line 5

May I ask why you have 2 session_start() function?

The reason why you got that error because you have 2 session_start() function! There should be only 1 session_start() function per page.

Try to put your session_start() function on top of your code instead of being in the middle.

From this:

<?php
include 'ProcessDAO.php';
$dest="";
if(isset($_POST['login'])){
session_start(); // i get an error in this line !!
$_SESSION['status']='online';
$_SESSION['breadcrumb']='home';
$pro = new ProcessDAO();
$dest = $pro->LogIn($_POST['username'],$_POST['password']);
}else{
session_start();
$dest ="Location: ../index.php";
session_destroy();
}
header($dest);
?>

To this:

<?php
session_start();
include ("ProcessDAO.php");
$dest="";
if(isset($_POST['login'])){
$_SESSION['status']='online';
$_SESSION['breadcrumb']='home';
$pro = new ProcessDAO();
$dest = $pro->LogIn($_POST['username'],$_POST['password']);
}else{
$dest = 'location: ../index.php';
session_destroy();
}
header($dest);
?>

thanks for that i did not get the same error again .. but what i get was these error when i transfer the session_start(); on top of my code ..

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\IPMS\process\ProcessDAO.php:1) in C:\xampp\htdocs\IPMS\process\login.php on line 14

Member Avatar for LastMitch

@syria718

thanks for that i did not get the same error again .. but what i get was these error when i transfer the session_start(); on top of my code ..

Did you write this code?

The reason why you got that error because you have 2 header which you should have only 1 header.

Take out line 14:

header($dest);

But i'm using it to redirect to the main page ..

thanks a lot i finally fixed the bug ..

Open the file in Notepad++ and change the encoding to Encode UTF-8 without BOM

My family i had this problem when i try to login in my admin root

Warning: include_once(/home/tts/public_html/wp-content/plugins/wp-hummingbird/core/class-abstract-module.php): failed to open stream: No such file or directory in /home/tts/public_html/wp-content/advanced-cache.php on line 24

Warning: include_once(): Failed opening '/home/tts/public_html/wp-content/plugins/wp-hummingbird/core/class-abstract-module.php' for inclusion (include_path='.:/opt/php71/lib/php') in /home/tts/public_html/wp-content/advanced-cache.php on line 24

Warning: include_once(/home/tts/public_html/wp-content/plugins/wp-hummingbird/core/modules/class-module-page-cache.php): failed to open stream: No such file or directory in /home/tts/public_html/wp-content/advanced-cache.php on line 25

Warning: include_once(): Failed opening '/home/tts/public_html/wp-content/plugins/wp-hummingbird/core/modules/class-module-page-cache.php' for inclusion (include_path='.:/opt/php71/lib/php') in /home/tts/public_html/wp-content/advanced-cache.php on line 25

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/tts/public_html/wp-content/advanced-cache.php:24) in /home/tts/public_html/wp-content/plugins/tshirtecommerce/tshirtecommerce.php on line 814

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/tts/public_html/wp-content/advanced-cache.php:24) in /home/tts/public_html/wp-content/plugins/tshirtecommerce/tshirtecommerce.php on line 814

Warning: Cannot modify header information - headers already sent by (output started at /home/tts/public_html/wp-content/advanced-cache.php:24) in /home/tts/public_html/wp-includes/pluggable.php on line 1265

Warning: Cannot modify header information - headers already sent by (output started at /home/tts/public_html/wp-content/advanced-cache.php:24) in /home/tts/public_html/wp-includes/pluggable.php on line 1268

someone could help

commented: A few problems. This is some 7+ YO discussion. If they didn't solve it by now. Make a new discussion. -3

For anyone who comes across this thread in the future, when you get the error that headers were already sent, it’s because once you echo anything out to the browser (HTML, text, etc) you can no longer send any additional http headers, which includes server-side redirects.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.