Eroare Cannot send session cookie - headers already sent
Discutii despre script-uri si coduri PHP-MySQL, precum si lucru cu XML in PHP.
-
alexinio3d
- Mesaje:96
Eroare Cannot send session cookie - headers already sent
M-am uitat in host si am observat urmatorile erori :
Cod: Selectaţi tot
[04-Nov-2012 17:59:28 UTC] PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent by (output started at /home/x15black/public_html/fifa/administrare/template/header.php:48) in /home/x15black/public_html/fifa/administrare/core/admin.php on line 2
[04-Nov-2012 17:59:37 UTC] PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent by (output started at /home/x15black/public_html/fifa/administrare/template/header.php:48) in /home/x15black/public_html/fifa/administrare/core/index.php on line 2
[04-Nov-2012 18:33:20 UTC] PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/x15black/public_html/fifa/administrare/template/header.php:48) in /home/x15black/public_html/fifa/administrare/core/clasament_update.php on line 2
[04-Nov-2012 19:14:52 UTC] PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/x15black/public_html/fifa/administrare/template/header.php:48) in /home/x15black/public_html/fifa/administrare/core/date_players.php on line 2
De ce oare imi da aceste erori ?
Siteuri create / configurate de mine :
SilvoProject.Ro ( Magazin Online ) :
SilvoProject.Ro
TreiSute.Ro ( Comunitate de gaming ) :
TreiSute.Ro
MarPlo
Mesaje:4343
Eroarea "Cannot send session cookie - headers already sent" apare cand se foloseste session_start() , setcookie() sau header() adaugate in script dupa o linie de cod care trimite date de iesire la browser, cum ar fi cu "echo", cod HTML, sau chiar un simplu spatiu inainte de "<?php".
session_start() trebuie adaugat la inceputul scriptului, inainte de orice date de iesire sau cod HTML, precum si inainte de fisiere incluse care afisseaza ceva in browser.
In eroarea de sus spune ca folosesti session_start() dupa ce au fost linii de cod care trimit date la server, probabil intr-un fisier inclus.
alexinio3d
Mesaje:96
Am pus spatiu dar tot asami da :-<
Cod: Selectaţi tot
[05-Nov-2012 16:05:42 UTC] PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/x15black/public_html/fifa/administrare/template/header.php:48) in /home/x15black/public_html/fifa/administrare/core/clasament_update.php on line 3
[05-Nov-2012 16:06:14 UTC] PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent by (output started at /home/x15black/public_html/fifa/administrare/template/header.php:48) in /home/x15black/public_html/fifa/administrare/core/admin.php on line 3
[05-Nov-2012 16:06:19 UTC] PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent by (output started at /home/x15black/public_html/fifa/administrare/template/header.php:48) in /home/x15black/public_html/fifa/administrare/core/index.php on line 3
Asa arata codul php :
index.php
Cod: Selectaţi tot
<?php
session_start();
if(isset($_SESSION['adminuser'])) { // Verificarea variabilei sesiune
?>
<table class="table table-hover">
<th align="center"><font color="#FF0000"><center>#</center></font></th>
<th align="center"><font color="#FF0000"><center>Echipa</center></font></th>
<th align="center"><font color="#FF0000"><center>M</center></font></th>
<th align="center"><font color="#FF0000"><center>V</center></font></th>
<th align="center"><font color="#FF0000"><center>E</center></font></th>
<th align="center"><font color="#FF0000"><center>I</center></font></th>
<th align="center"><font color="#FF0000"><center>GD</center></font></th>
<th align="center"><font color="#FF0000"><center>GP</center></font></th>
<th align="center"><font color="#FF0000"><center>G</center></font></th>
<th align="center"><font color="#FF0000"><center>Pct.</center></font></th>
<?php
$info = mysql_query("SELECT * FROM clasament_echipa ORDER by `puncte` DESC, `golaveraj` DESC");
$loc = 1;
while ($row = mysql_fetch_array($info))
{
$puncte = $row['puncte'];
$golaveraj = $row['golaveraj'];
$echipa = $row['echipa'];
$meciuri = $row['meciuri'];
$victori = $row['victori'];
$egaluri = $row['egaluri'];
$infrangeri = $row['infrangeri'];
$goluri_date = $row['goluri_date'];
$goluri_luate = $row['goluri_luate'];
print( " <tr class='info'>
<td class='rank'><center>$loc.</center></td>
<td class='echipa'><center>$echipa</center></td>
<td class='meciuri'><center>$meciuri</center></td>
<td class='victori'><center>$victori</center></td>
<td class='egaluri'><center>$egaluri</center></td>
<td class='infrangeri'><center>$infrangeri</center></td>
<td class='goluri_date'><center>$goluri_date</center></td>
<td class='goluri_luate'><center>$goluri_luate</center></td>
<td class='golaveraj'><center>$golaveraj</center></td>
<td class='puncte'><center>$puncte</center></td></tr>" );
$loc++;
}
?>
</table>
<?php
}
else { // Daca nu exista sesiunea atunci va da urmatoarea eroare
echo '<div class="alert alert-block"><center>Nu aveti deschisa o sesiune de lucru</center></div>';
}
?>
admin.php
Cod: Selectaţi tot
<?php
session_start();
if(isset($_POST['useradmin']) && isset($_POST['passadmin'])){ // incercarea utilizatorului de a deschide o sesiune de lucru
$useradmin = $_POST['useradmin'];
$passadmin = $_POST['passadmin'];
$query = "SELECT * FROM user_admin WHERE useradmin = '$useradmin' and passadmin = '$passadmin'";
$result = mysql_query($query);
if (!$result){
echo 'Nu pot rula interogarea';
exit;
}
$row = mysql_fetch_row($result);
$count = $row[0];
if($count > 0){
$_SESSION['adminuser'] = $useradmin;
}
}
if(isset($_SESSION['adminuser'])){ // Daca sa deschis o sesiune noua cu succes
echo '<div class="alert alert-success"><center>Conectare s-a terminat cu succes<meta http-equiv="refresh" content="5" url="./index.php" /></center><br /><center>Daca nu sunteti redirectionat in 5 secunde atunci dati click <a href="./index.php">aici</a></center><br /><center>Pentru a te deloga apasa <a href="./logout.php">aici</a></center></div>';
}
else{
if(isset($useradmin)){ // daca sa incercat deschiderea unei sesiuni noi si nu s-a reusit
echo '<div class="alert alert-success"><center>Conectare s-a terminat cu succes<meta http-equiv="refresh" content="5" url="./index.php" /><br /><center>Daca nu sunteti redirectionat in 5 secunde atunci dati click <a href="./index.php">aici</a></center></div>';
}
else { // daca sa incercat deschiderea unei sesiuni de lucru sau daca a fost inchisa
echo '<div class="alert alert-block"><center>Nu aveti deschisa o sesiune de lucru</center></div>';
}
?>
<form method="post" action="admin.php">
<center><h5>User Admin :</h5> <input type="text" name="useradmin" placeholder="User" /></center>
<center><h5>Pass Admin :</h5> <input type="password" name="passadmin" placeholder="Parola" /></center>
<center><input type="submit" name="submit" value="Autentificare" class="btn btn-primary"/></center>
</form>
<?php
}
?>
clasament_update.php
Cod: Selectaţi tot
<?php
session_start();
if(isset($_SESSION['adminuser'])) { // Verificarea variabilei sesiune
?>
<form action="./update.php" method="post">
<table class="table table-hover">
<tr class='info'><td class='echipa'>
<select name="echipa" id="echipa">
<?php
$muta_la_echipa=@mysql_query("SELECT * FROM `clasament_echipa` ORDER by `echipa`");
while($rand2=@mysql_fetch_array($muta_la_echipa))
{
$echipa = $rand2['echipa'];
print("<option value='$echipa' selected='selected'>$echipa</option>");
}
?>
</select></td>
<td class='meciuri'><center><font color="#FF0000"><b>M : </b></font><input name='meciuri' type='text' size='30' maxlength='3' style='width:20px' id='meciuri' class='tbox' /></center></td>
<td class='victori'><center><font color="#FF0000"><b>V : </b></font><input name='victori' type='text' size='30' maxlength='3' style='width:20px' id='victori' class='tbox' /></center></td>
<td class='egaluri'><center><font color="#FF0000"><b>E : </b></font><input name='egaluri' type='text' size='30' maxlength='3' style='width:20px' id='egaluri' class='tbox' /></center></td>
<td class='infrangeri'><center><font color="#FF0000"><b>I : </b></font><input name='infrangeri' type='text' size='30' maxlength='3' style='width:20px' id='infrangeri' class='tbox' /></center></td>
<td class='goluri_date'><center><font color="#FF0000"><b>GD : </b></font><input name='goluri_date' type='text' size='30' maxlength='3' style='width:20px' id='goluri_date' class='tbox' /></center></td>
<td class='goluri_luate'><center><font color="#FF0000"><b>GP : </b></font><input name='goluri_luate' type='text' size='30' maxlength='3' style='width:20px' id='goluri_luate' class='tbox' /></center></td>
<td class='golaveraj'><center><font color="#FF0000"><b>G : </b></font><input name='golaveraj' type='text' size='30' maxlength='3' style='width:20px' id='golaveraj' class='tbox' /></center></td>
<td class='puncte'><center><font color="#FF0000"><b>Pct. : </b></font><input name='puncte' type='text' size='30' maxlength='3' style='width:20px' id='puncte' class='tbox' /></center></td></tr>
</table>
<center><input name="submit" type="submit" value="Update" class="btn btn-primary" /></center>
</form>
<?php
}
else { // Daca nu exista sesiunea atunci va da urmatoarea eroare
echo '<div class="alert alert-block"><center>Nu aveti deschisa o sesiune de lucru</center></div>';
}
?>
Siteuri create / configurate de mine :
SilvoProject.Ro ( Magazin Online ) :
SilvoProject.Ro
TreiSute.Ro ( Comunitate de gaming ) :
TreiSute.Ro
steell
Mesaje:190
in index.php nu este scris corect.
ai pus conditia
apoi ai inchis codul php cu " ?> ".
Din moment ce ai scris " ?> " codul respectiv se opreste acolo, chiar daca deschizi mai jos alte coduri " <?php " acestea vor lucra independent de celelalte, nu au treaba cu ele.
Daca vrei sa afisezi cu php elemente html folosesti echo
Insa sa scrii atributele html intre ghilimele duble " daca le pui simple vei specifica ca acolo se inchide instructiuena echo.
banuiesc ca si celelalte fisiere de mai jos sunt scrie asemanator (aceeasi greseala).
alexinio3d
Mesaje:96
Tot asa
Cod: Selectaţi tot
[05-Nov-2012 17:29:40 UTC] PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent by (output started at /home/x15black/public_html/fifa/administrare/template/header.php:48) in /home/x15black/public_html/fifa/administrare/core/admin.php on line 3
[05-Nov-2012 17:29:40 UTC] PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/x15black/public_html/fifa/administrare/template/header.php:48) in /home/x15black/public_html/fifa/administrare/core/admin.php on line 3
[05-Nov-2012 17:30:15 UTC] PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent by (output started at /home/x15black/public_html/fifa/administrare/template/header.php:48) in /home/x15black/public_html/fifa/administrare/core/admin.php on line 3
[05-Nov-2012 17:30:15 UTC] PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/x15black/public_html/fifa/administrare/template/header.php:48) in /home/x15black/public_html/fifa/administrare/core/admin.php on line 3
[05-Nov-2012 17:30:17 UTC] PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent by (output started at /home/x15black/public_html/fifa/administrare/template/header.php:48) in /home/x15black/public_html/fifa/administrare/core/index.php on line 3
[05-Nov-2012 17:30:17 UTC] PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/x15black/public_html/fifa/administrare/template/header.php:48) in /home/x15black/public_html/fifa/administrare/core/index.php on line 3
Scriptul index.php asa arata de data asta :
Cod: Selectaţi tot
<?php
session_start();
if(isset($_SESSION['adminuser'])) { // Verificarea variabilei sesiune
echo '
<table class="table table-hover">
<th align="center"><font color="#FF0000"><center>#</center></font></th>
<th align="center"><font color="#FF0000"><center>Echipa</center></font></th>
<th align="center"><font color="#FF0000"><center>M</center></font></th>
<th align="center"><font color="#FF0000"><center>V</center></font></th>
<th align="center"><font color="#FF0000"><center>E</center></font></th>
<th align="center"><font color="#FF0000"><center>I</center></font></th>
<th align="center"><font color="#FF0000"><center>GD</center></font></th>
<th align="center"><font color="#FF0000"><center>GP</center></font></th>
<th align="center"><font color="#FF0000"><center>G</center></font></th>
<th align="center"><font color="#FF0000"><center>Pct.</center></font></th>';
$info = mysql_query("SELECT * FROM clasament_echipa ORDER by `puncte` DESC, `golaveraj` DESC");
$loc = 1;
while ($row = mysql_fetch_array($info))
{
$puncte = $row['puncte'];
$golaveraj = $row['golaveraj'];
$echipa = $row['echipa'];
$meciuri = $row['meciuri'];
$victori = $row['victori'];
$egaluri = $row['egaluri'];
$infrangeri = $row['infrangeri'];
$goluri_date = $row['goluri_date'];
$goluri_luate = $row['goluri_luate'];
print( " <tr class='info'>
<td class='rank'><center>$loc.</center></td>
<td class='echipa'><center>$echipa</center></td>
<td class='meciuri'><center>$meciuri</center></td>
<td class='victori'><center>$victori</center></td>
<td class='egaluri'><center>$egaluri</center></td>
<td class='infrangeri'><center>$infrangeri</center></td>
<td class='goluri_date'><center>$goluri_date</center></td>
<td class='goluri_luate'><center>$goluri_luate</center></td>
<td class='golaveraj'><center>$golaveraj</center></td>
<td class='puncte'><center>$puncte</center></td></tr>" );
$loc++;
}
echo '</table>';
}
else { // Daca nu exista sesiunea atunci va da urmatoarea eroare
echo '<div class="alert alert-block"><center>Nu aveti deschisa o sesiune de lucru</center></div>';
}
?>
Siteuri create / configurate de mine :
SilvoProject.Ro ( Magazin Online ) :
SilvoProject.Ro
TreiSute.Ro ( Comunitate de gaming ) :
TreiSute.Ro
archemorus
Mesaje:29
Daca folosesti fisiere incluse pentru generarea paginilor, ai grija sa nu ai
session_start(); in fiecare dintre ele, ci doar in primul.
De exemplu, daca codul paginii tale e ceva de genul:
Cod: Selectaţi tot
<?php
include('header.php');
cod specific pagina
...
include('footer.php');
?>
Tu trebuie sa ai session_start(); doar in "header.php", inainte de a trimite orice alta data catre server.
Din erorile care sunt afisate eu inteleg ca tu ai deja session_start(); in fisierul: "
/home/x15black/public_html/fifa/administrare/template/header.php", care banuiesc ca este inclus la generarea fiecarei pagini.
Bafta!
alexinio3d
Mesaje:96
In "header.php" nu am nici o session_start(); , dar am observat ca-mi da eroarea din cauza versiunii PHP care ruleaza pe webhosting, pentru ca pe pc la mine merge scriptul cum trebuie, iar cand il urc imi da eroare .
Siteuri create / configurate de mine :
SilvoProject.Ro ( Magazin Online ) :
SilvoProject.Ro
TreiSute.Ro ( Comunitate de gaming ) :
TreiSute.Ro
archemorus
Mesaje:29
In cazul asta, daca ai un host gratuit, nu stiu daca poti sa faci prea multe, doar sa schimbi hostul (majoritatea host-urilor gratuite au diferite restrictii si nu poti utiliza toate functiile php). Daca ai un host platit, atunci i-a legatura cu ei si incearca sa afli daca au diferite restrictii care ar putea provoca eroarea din scriptul tau.
Bafta.
Subiecte similare
- Eroare la un formular cu PHP
PHP - MySQL - XML
Primul mesaj
Salut. Am si eu o problema. In primul rand nu stiu daca am postat unde trebuie si am cautat pe forum ceva asemanator cu problema mea insa nu am...
Ultimul mesaj
Am rezolvat. Multumesc oricum pentru timpul acordat. Am folosit phpmailer pt ca cei de unde am webhostul asa lucreaza. Multumesc inca o data !
- Eroare de variabila in php 8
PHP - MySQL - XML
Primul mesaj
Salut
Am trecut la php 8 si imi da eroarea asta
Warning: Undefined variable $page in G:\site\htdocs\system\site\page.php on line 16
in...
Ultimul mesaj
Imi mai da eroarea asta
Warning: Undefined array key message
iar eu am asa
$message=$_POST ;
Edit,
rezolvat cu
$message='';
if (isset($_POST...
- Eroare la incarcare json
JavaScript - jQuery - Ajax
Primul mesaj
Bună Marius
Cum rezolv să imi încarce tot fișierul .json
eoroare la
//fetch(endpoint)
//.then(blob => blob.json())
//.then(data =>...
Ultimul mesaj
Fisierul json de la acea adresa are peste 50 MB, e cam mare pentru preluare si procesare direct in pagina (client side) cu javascript.
A) Indicat...
- Eroare curs valutar
Scripturi de pe site
Primul mesaj
Salutare, folosesc de ceva vreme scriptul pentru curs valutar, care e foarte ok.
Recent la o validare a aparut eroarea
Uncaught SyntaxError:...
Ultimul mesaj
Nu e nici o problema.
Din ce am inteles, eroarea apare doar in validare, de la rularea codului care trebuie sa acceseze prin ajax un alt fisier.
- Eroare citire pagina cu file_get_contents
PHP - MySQL - XML
Primul mesaj
Buna ziua,
Vreau sa preiau informatiile din aceasta adresa si sa o afisez intr-o alta pagina php
URL: //79.114.46.127:5819/
Scriptul pe care...
Ultimul mesaj
Imi pare rau, mai mult nu stiu cum sa te ajut, posibil sa fie ceva cu SSL, dar nu cunosc.
Am testat scripturile; codul cu cURL e bun, a mers bine...