Salve a tutti, sto provando ad usare delle session per gestire dei login sul mio sito il problema mi sorge quando vado ad effettuare il login e mi da 4 righe di errore :
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Users\Utente\Desktop\sitophp\sitozio\login2.php :361) in C:\Users\Utente\Desktop\sitophp\sitozio\login2.php on line 376
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Users\Utente\Desktop\sitophp\sitozio\login2.php :361) in C:\Users\Utente\Desktop\sitophp\sitozio\login2.php on line 376
Warning: Cannot modify header information - headers already sent by (output started at C:\Users\Utente\Desktop\sitophp\sitozio\login2.php :361) in C:\Users\Utente\Desktop\sitophp\sitozio\login2.php on line 388
Vi posto solo il codice php presente nella mia pagina login2.php , in quanto ne ho fatte 2 di pagine: una con solo il codice html e relativo form , mentre un altra con l'apertura della sessione.
<?php
$con = mysql_connect("localhost","root","ascent");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("utenti", $con);
$sql="SELECT username, password FROM utenti where username='$_POST[username]' and password='$_POST[password]'
union
select username, password from aziende where username='$_POST[username]' and password='$_POST[password]'";
$risultato=mysql_query($sql);
$prova=mysql_num_rows($risultato);
if($prova==1){
while($row = mysql_fetch_array($risultato)) {
session_start();
$idutente = $row['ID'];
$nomeutente = $row['username'];
$_SESSION['id_utente'] = $idutente;
$_SESSION['nome_utente'] = $nomeutente;
// e infine reindirizzo l'utente nella pagina protetta da login
header("location: lavori.php");
echo "Login effettuato con successo";
}
}
else {
echo "Dati incorretti";
}
mysql_close($con);
?>
Premetto che senza la session funziona ( o abbastanza in quanto l'ultimo warning me lo da anche se non è presente , documentandomi ho visto che potrebbe essere un problema relativo all'header)