Warning: Cannot modify header information...

hackersatifal

Utente Attivo
9 Ago 2012
238
0
0
Salve a tutti,
ho scritto uno script in php-html, ma quando voglio modificare l'header con un indirizzo mi visualizza questo errore: 'Warning: Cannot modify header information - headers already sent by (output started at /membri/sito/pagina.php:72) in /membri/sito/pagina.php on line 115'.
Come posso risolvere?
Ecco il codice:
PHP:
<?php   
if(!isset($_SESSION)){session_start();}     
if(!isset($_SESSION['utente'])){     
    header("location: login2.php?azione=login");    
    exit();      
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="style.css"> 
<script type="text/javascript" src="jquery.js"></script> 
<script type="text/javascript" src="tipsy.js"></script> 
<script type="text/javascript"> 
        $(document).ready(function(){ 
$("[title]").tipsy({fade: true});
}); 
</script>
<style type="text/css">
a.scrittemenu {text-decoration:none}
a.hover{text-decoration:underline}
a.nomeutentebarra {text-decoration:none}
a:hover {text-decoration:underline}
a.logout {text-decoration:none}
a:hover {text-decoration:underline}
a.modifica_dati {text-decoration:none}
a:hover {text-decoration:underlinee}
p.saluto{margin-top:8%; margin-left:25%; color:white; font-family:'Palatino Linotype', 'Book Antiqua', Palatino, serif; font-size:200%; font-weight:bold}
a.profilo{margin-left:30%; font-family:'Palatino Linotype', 'Book Antiqua', Palatino, serif; font-size:150%; color:white}
a:hover {text-decoration:underline}
div.sidebar1 {float: left; width:25%; height:100%; background-color:#0165B6; border:1px solid #48aed1; margin-top:-47%; margin-left:3%}
div.sidebar2 {width:71%; height:100%; background-color:#0165B6; border:1px solid #48aed1; margin-top:0%; margin-left:29%}
p.username {text-decoration:none; color:white; font-size:120%; font-family:'Palatino Linotype', 'Book Antiqua', Palatino, serif; margin-bottom:5%; margin-top:5%}
p.noresult {color:white; font-size:120%; font-family:'Palatino Linotype', 'Book Antiqua', Palatino, serif; margin-bottom:5%; margin-top:5%}
p.bacheca {color:black; font-size:120%; font-family:'Palatino Linotype', 'Book Antiqua', Palatino, serif; margin-bottom:5%; margin-top:5%}
::-webkit-input-placeholder {font-size:90%; font-family:'Palatino Linotype', 'Book Antiqua', Palatino, serif}
img {max-width:52%;max-height:52%; margin-top:-21%; border: 1px solid black; padding: 2%; background-color:white}
</style>
<script type="text/javascript">
<!--
 
var stile = "top=300, left=300 width=400, height=10, status=no, menubar=no, toolbar=no scrollbars=no";
 
function Popup(apri) 
{
  window.open(apri, "", stile);
}
//-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>KnowEveryone</title>
</head>
<body style="background-color:#036; width: 100%; height: 100%; display: block">
<div id="barra" style="height: 8%; position: fixed; top: 0px; bottom: 0; left: 0; width: 100%; background-color: #006699; border-bottom: 1px solid #133783; position:fixed !important"> 
<p style="margin-top:1%; margin-bottom:1%; margin-left:1%; color:#FFF; font-family:'Palatino Linotype', 'Book Antiqua', Palatino, serif; font-size:150%; font-weight:bold; text-align:left">KnowEveryone <a class="nomeutentebarra" href="profile2.php" style="color:white"><?php $utente= ucwords($_SESSION['utente']); print "($utente)";?></a><a class="logout" href="login2.php?azione=logout" style="color:#FFF; font-family:'Palatino Linotype', 'Book Antiqua', Palatino, serif; font-size:100%; font-weight:bold; margin-right:1%; margin-left:2%" title="Esci">Esci</a></p> 
</div> 
<?php 
include 'header.php';  
print "<p class='saluto'>$utente</p>"; 
?>
</div>
<div id="menu" style="width:71%;background-color: #0165B6; margin-left: 29%; font-size: 160%; font-family:'Palatino Linotype', 'Book Antiqua', Palatino, serif; color: white; border:1px solid #48aed1;">
<label style="margin-left: 0%"> | </label>
<a href="note.php" style="margin-top:5px; margin-left: 1%; background-color: #0165B6; margin-right: 1%; font-size: 90%; font-family:'Palatino Linotype', 'Book Antiqua', Palatino, serif; color: white" class="scrittemenu" title="Note">Note</a>
<label> | </label>
<a href="chatcomune.php" style="margin-top:5px; margin-left: 1%; background-color: #0165B6; margin-right: 1%; font-size: 90%; font-family:'Palatino Linotype', 'Book Antiqua', Palatino, serif; color: white" class="scrittemenu" title="Chat comune">Chat comune</a>
<label> | </label>
<a href="profile2.php" style="margin-top:5px; margin-left: 1%; background-color: #0165B6; margin-right: 1%; font-size: 90%; font-family:'Palatino Linotype', 'Book Antiqua', Palatino, serif; color: white" class="scrittemenu" title="Bacheca">Bacheca</a>
<label> | </label>
</div>
<div class="sidebar2"> 
<iframe name="visualizza" width="70%" height="80%" frameborder="1" src="bacheca_visualizza6.php" style="background-color:white; border:1px solid white" scrolling="yes"></iframe>
<iframe name="visualizza3" width="29%" height="80%" src="chat/chatpiccola.php"></iframe>
<center><iframe name="visualizza2" width="100%" height="8%" frameborder="1" src="bacheca_input.php" style="background-color:white; border:1px solid #CCCCCC; background-color:#0165B6" scrolling="no"></iframe></center> 
</div> 
<table border=0 width=100% cellpadding=0 cellspacing=0>
<div class="sidebar1"> 
<center> 
<?php 
error_reporting(E_ALL); 
$dati = mysql_query("SELECT foto FROM utenti WHERE username='".$_SESSION['utente']."'"); 
$risultato= mysql_fetch_array($dati); 
$_SESSION['foto'] = $risultato['foto']; 
echo <<<EOF
<a href="javascript:Popup('modifica_foto.php')" alt="Modifica la tua foto cliccando qui!" title="Modifica la tua foto cliccando qui!"><img src="uploads/{$risultato['foto']}"></a>
EOF;
?> 
<iframe name="visualizza" width="65%" height="20%" frameborder="1" src="infopersonali.php" style="margin-top:10%; background-color:white; border:1px solid black"></iframe> 
<p style="margin-top:5%"><a class= "modifica_dati" href="modifica_dati2.php" style="color:white; font-size:120%; font-family:'Palatino Linotype', 'Book Antiqua', Palatino, serif" title="Modifica i tuoi dati personali cliccando qui!">[modifica dati]</a></p> 
<iframe name="visualizza" width="65%" max-height="25%" frameborder="1" src="statoprofilo.php" style="background-color:white; border:1px solid black"></iframe> 
<?php  


            if(!isset($_POST['post'])){ ?> 
             
                <form method="post" action="#" id="modificastato" style="alignment-adjust:central"> 
                     
                    <ul> 
                        <label for="post" style="font-size:120%; color:white; margin-left:-11%; font-family:'Palatino Linotype', 'Book Antiqua', Palatino, serif" title="Inserisci il tuo stato nel campo sottostante!">Inserisci il tuo stato:</label> 
                        <br> 
                            <input type="text" name="post" id="post" style="width:65%; height:120%; font-size:120%; border:1px solid black; margin-left:-12%; margin-top:5%" title="Inserisci il tuo stato qui!"/><br> 
                            </ul> 
                        <input type="submit" name="invia" id="salva" value="Salva" style="width:20%; height:9%; color:black; background-color:white; border:1px solid black; font-family:'Palatino Linotype', 'Book Antiqua', Palatino, serif; font-size:110%; margin-bottom:5%" title="Salva"/> 
                </form>         
    <?php    } else { 
                                 
                // Valori del form 
                 
                $post = mysql_real_escape_string($_POST['post']); 
                 
                        // Invia dati alla tb utenti 
                         
                        $query="UPDATE utenti SET post='".$post."' WHERE  username='".$_SESSION['utente']."'";  
$inviautente=mysql_query($query) or die(mysql_error()); 
header("Refresh: 1; URL= profile2.php?id={$_SESSION['utente']}#"); 
                         
                         
                        } 
    ?> 
<?php 
            if(!isset($_POST['cerca'])){ ?> 
             
                <form method="post" action="#" id="formricerca" style="alignment-adjust:central"> 
                     
                    <input type="text" name="username" id="username" style="margin-bottom:5%; width:65%; height:9%; font-size:120%; border:1px solid black"; placeholder="Cerca una persona qui" title="Cerca una persona qui!"/> 
                    <input type="submit" name="cerca" id="cerca" value="Cerca" style="width:20%; height:9%; color:black; background-color:white; border:1px solid black; font-family:'Palatino Linotype', 'Book Antiqua', Palatino, serif; font-size:110%; margin-bottom:5%" title="Cerca"/> 
                </form>         
    <?php    } else { 
                                 
                        $username = mysql_real_escape_string($_POST['username']); 
                        if($username == ""){ 
                     
                        echo "Attenzione, devi compilare tutti i campi"; 
                     
                        } else { 
                         
                        $recuperadati = mysql_query("SELECT * FROM utenti WHERE username= '$username'"); 
                                  
                                $verificadati = mysql_num_rows($recuperadati);  
                                  $risultato = ucwords($username);
$risultato2 = strtolower($risultato);
if($verificadati == 1){
                                echo "<br><a href='result_search2.php?id=".$risultato2."' class='username'>$risultato</a>"; 

                                    
                                    } else {
                                      echo "<p class='noresult'>Nessun risultato trovato!</p>";  
                                  
                                    }  
                              
                            }  
                          
                        }  
                      
?>
</center>
</div>
<center><p style="font-family:'Palatino Linotype', 'Book Antiqua', Palatino, serif; font-size:150%; color:white">KnowEveryone: una produzione di Giuseppe Ferrara</p></center>
</div>
</body>  
</html>
Grazie a tutti in anticipo per il vostro aiuto,
hackersatifal.
 

criric

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
21 Ago 2010
5.607
54
48
TN
Ciao,
non è consentito stampare codice html prima della funzione header() nemmeno uno spazio vuoto, nemmeno se presente in un file incluso

usa location.href al posto di header e dovresti risolvere

PHP:
if (!isset($_SESSION['utente'])) {
    echo "<script type='text/javascript'>";
    echo "location.href='login2.php?azione=login';";
    echo "</script>";
}
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.042
149
63
PR
www.borgo-italia.it
ciao
se si deve e conviene usare header (conviene perche essendo php l'eventuale indirizzamento non è visibile contrariamente al js e tag meta) si può provare a mettere alla prima riga (nemmeno uno spazio prima)
PHP:
<?php
ob_start();
//...tutto quello che serve sia php che html
?>
e in fondo dopo 
</html>
<?php
ob_end_flush();
?>
 
Discussioni simili
Autore Titolo Forum Risposte Data
G [PHP] Warning: Cannot modify header information - headers already sent by PHP 3
L Warning: Cannot modify header information - headers already sent by... PHP 9
M Warning: Cannot modify header information - headers already sent by (output started a PHP 1
H Warning: session_start() [function.session-start]: Cannot send session cache limiter PHP 8
M Warning: session_start(): Cannot send session cache... ???? PHP 5
F [MySQL] Warning 1265 data truncated for column... MySQL 5
B Warning: mysql_connect(): Access denied for user 'DIREZIONE'@'81.88.55.179' (using password: YES) PHP 6
G [PHP] Problema - Warning: session_start() [function.session-start] PHP 9
G Warning: mysql_num_rows() che problema è? PHP 3
P Warning: mysqli_query() expects parameter 1 to be mysqli PHP 2
C ERRORE: Warning: move_uploaded_file()... come risolverlo? PHP 1
JackIlPazzo Warning: Invalid argument supplied for foreach() PHP 1
N warning su sessione PHP 2
F Warning: Invalid argument supplied for foreach() PHP 3
A Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given PHP 17
L Problema messaggio d'errore -Warning: mysqli_num_rows() expects parameter 1 to be mysqli_ etc etc... PHP 2
pup3770 Su Mac funziona - su windows da warning PHP 9
E Warning: session_start() PHP 1
P Warning: mysql_num_rows() expects parameter 1 to be resource, array given in PHP 9
A Warning: mysql_result() expects parameter 1 to be resource, boolean given MySQL 2
I Warning: Division by zero in Joomla 0
S Help : Warning: mail() [function.mail] PHP 2
P Warning email() PHP 116
catellostefano CLASSE PHP Warning: mysql_fetch_assoc() expects parameter 1 to be resource PHP 2
Frank10 Problema w3c warning HTML5 -.-" HTML e CSS 5
neo996sps Warning su redirect della pagina PHP 9
M Warning: mysql_query() expects parameter 2 to be resource, boolean given PHP 3
S Warning sulle sessioni, come fare? PHP 1
catellostefano Problema per richiamare file xml -- Warning: DOMDocument::load() [domdocument.load]: PHP 0
L Warning: mysql_fetch_assoc() expects parameter 1 to be resource, null given in .... PHP 2
S errore warning mysql_ferch_array() e mysql_free_result() PHP 5
A Warning strano PHP 2
JellyBelly Warning Uso Rename PHP 2
W Warning: main(./WEB-INF/etc/config.php): PHP 3
M Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in PHP 6
C problema con un warning PHP 0
L Error Code: 1215. Cannot add foreign key constraint MySQL 3
M non static method cannot be referenced from a static context Java 1
M Errore pagina php 'Cannot detect primary key' PHP 8
G Errore Cannot read property 'childNodes' of undefined per mancanza nodo nel file xml XML 6
romeocharly [WordPress] .../ffmpeg/ffmpeg32.so: cannot execute binary file" WordPress 11
A Errore: cannot call methods on dialog prior to initialization; attempted to call method 'open' jQuery 4
JackIlPazzo Cannot add foreign key constraint MySQL 1
J Errore the value cannot be null or empty ASP.NET 1
Nik Cannot send session cache limiter - ERRORE utilizzando session_start(); PHP 3
L Error: int cannot be dereferenced Java 1
filippino Fatal error: Cannot redeclare (function) PHP 2
L Cannot find executable for CFBundle Sviluppo app per iOS 0
L ITSM-9000 the bundle identifier cannot be changed from the current value Sviluppo app per iOS 0
D Cannot find XELDZ in all drives Windows e Software 0

Discussioni simili