0
I have already investigated here in Stack about such error, but I have not found a way to solve my specific problem.
I have a file saved as PHP that works as an "index", basically full of HTML. About halfway through the structure of the file, in body
, I want to insert a visit counter into the site and an online user display. I made a PHP file for each of these two things and included (with "include") within this "index". However, the following error occurred:
"Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\wamp64\www\administrador\indexadmin.php:192) in C:\wamp64\www\administrador\usuariosonline.php on line 3
Call Stack
# Time Memory Function Location
1 0.0007 244648 {main}( ) ...\indexadmin.php:0
2 0.0050 265496 include( 'C:\wamp64\www\administrador\usuariosonline.php' ) ...\indexadmin.php:206
3 0.0050 265544 session_start ( ) ...\usuariosonline.php:3"
How to solve?
Here are the codes:
"index.php" is this (no body):
<div class="col col-3">
<div class="visitassite">
<h4>Visitas ao Site</h4>
<p>
<?php include "totalvisitas.php"; ?>
</p>
</div>
</div>
<div class="col col-3">
<div class="usuariosonline">
<h4>Usuários Online</h4>
<p>
<?php include "usuariosonline.php"; ?>
</p>
</div>
</div>
The two php files that are being included are these:
Filing cabinet total visits.php:
<?php
try {
$pdo = new PDO('mysql:host=localhost;dbname=contador', 'root', '');
}catch (PDOException $e){
echo $e->getMessage();
}
$selecionar = $pdo->prepare("SELECT * FROM visitas");
$selecionar->execute();
$resultados = $selecionar->fetchAll(PDO::FETCH_ASSOC);
foreach($resultados as $results):
echo "Total de visitas ao site: ".$results['visitas'];
$contar = $results['visitas'] + 1;
$update = $pdo->prepare("UPDATE visitas SET visitas=:visitas");
$update->bindValue(':visitas', $contar);
$update->execute();
endforeach;
?>
The other is this one (usuariosonline.php):
<?php
session_start();
$session_path = session_save_path();
$visitors=0;
$handle = opendir($session_path);
while (($file = readdir ($handle)) != FALSE)
{
if ($file!="."&&$file!="..")
{
if (preg_match("/^sess/",$file))
$visitors++;
}
}
echo "Há $visitors visitantes online.";
?>
You researched ? Error logging in administrative panel - Session_start.
– NoobSaibot
A. Goes posted on my server the 3 files, I tested, and here with me gave no mistake no. The strange is the number of visitors online. See http://kithomepage.com/sos/session_start.php
– user60252
Hi wmsouza! I researched about the problem... but what I seek (and maybe I was happy in the title but unhappy in the description of the post) is the way to fix in my specific case... maybe something like André answered... The solution well explained was not found by me in the forum (maybe I have not exhausted the research, but I have made a lot of progress...). Perhaps such a solution, since it is such a common problem, if well detailed, can be of great use to many of little experience like me... Leo, thank you for the test! By elimination, you have already said enough! Thank you all for the speed in the answers!
– André Góes
Related: Error - "Cannot Modify header information - headers already sent"
– bfavaretto