zuko Posted October 31, 2008 Share Posted October 31, 2008 I've just knocked up a quick login system using cookies and when I run my login script I get this error: Warning: Cannot modify header information - headers already sent by (output started at \var\www\web\header.php:9) in \var\www\web\login.php on line 31 here is my header.php script: <?php session_start(); require_once "inc.php"; ?> <html> <head> <title>.: Video Streaming >></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- .kiri { background-image: url(gambar/tmp_11bg.gif); background-repeat: repeat-y; } .kanan { background-image: url(gambar/tmp_10bg.gif); background-repeat: repeat-y; width: 40px; } .tekssatu { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color: #FFFFFF; } .teksdua { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color: #000000; } .tekstiga { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #000000; } .tengah { background-image: url(gambar/tmp_02bg.gif); background-repeat: repeat-x; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #FFFFFF; } a:link,a:active,a:visited { color : #FF6600; text-decoration: none; } a:hover { text-decoration: underline; color : #FF0000; } .mainmenu { font-weight: bold; font-size: 12px; color : #006699; text-decoration: none; } a.mainmenu { test-decoration: none; color : #006699; } a.mainmenu:hover{ text-decoration: underline; color : #DD6900; } input,textarea, select { color : #000000; font: normal 11px Verdana, Arial, Helvetica, sans-serif; border: 1px #000000; } /* The text input fields background colour */ input.post, textarea.post, select { background-color : #FFFFFF; } input { text-indent : 2px; } /* The buttons used for bbCode styling in message post */ input.button { background-color : #EFEFEF; color : #000000; font-size: 11px; font-family: Verdana, Arial, Helvetica, sans-serif; border: 1px solid #000000; } /* The main submit button option */ input.mainoption { background-color : #FAFAFA; font-weight : bold; } input.maindua { background-color : #FAFAFA; font-weight : bold; border: 1px solid #000000; } .garis { border: 1px solid #000000; } .judul { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: bold; color: #FF6600; text-decoration: none; } tr.header { font-weight: bold; border: solid #000000; height: 20px; bakground-color: #A6D2FF; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; color: #FF6600; text-decoration: none; } --> </style> </head> <body background="gambar/bg.gif"> <table width="646" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="297"><img src="gambar/tmp_01.gif" width="297" height="51"></td> <td class="tengah" width="100%"><marquee direction="left" scrollamount="10" scrolldelay="200">Welcome to Adaptive Video Streaming with MPEG-4 Encoding</marquee></td> <td width="40" align="right"><img src="gambar/tmp_03.gif" width="40" height="51"></td> </tr> </table></td> </tr> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="162" height="70"><img src="gambar/tmp_04.gif" width="162" height="70"></td> <td width="161"><img src="gambar/tmp_05.gif" width="161" height="70"></td> <td width="162"><img src="gambar/tmp_06.gif" width="162" height="70"></td> <td width="161"><img src="gambar/tmp_07.gif" width="161" height="70"></td> </tr> </table></td> </tr> <tr> <td width="100%"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="kiri" width="122" valign="top" height="100%"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="122" height="126"><img src="gambar/tmp_08.gif" width="122" height="126"></td> </tr> <tr> <td height="100%" align="center" background="gambar/tmp_11bg.gif" class="kiri"> <? if (emptyString($_COOKIE[id])){ ?> <form action="login.php" method="post"> <div class="tekssatu">Username : <br> <input type="text" name="usrnm" size="10" class="mainoption"> <br> Password : <br> <input name="psw" type="password" size="10" class="mainoption"> <br><br> <input type="submit" value="login >>" class="button"> </div> </form> <? } else { ?> <div class="mainmenu"> <a href="/admin.php"><img src="gambar/administrator.gif" width="38" height="38" border="0"><br> Administrator</a> <br> <a href="/login.php?mod=logout"><img src="gambar/logout.gif" border="0"><br> LOGOUT</a></div><br> <div class="teksdua">Camera<br>Position<br><br> <table width="70" border="0" cellpadding="0" cellspacing="5" class="tekssatu"> <tr align="center"> <td><a href="/cgi-bin/kamera_cw.cgi">cw</a></td> <td><a href="/cgi-bin/kamera_ccw.cgi">ccw</a></td> /*Script di atas digunakan untuk menggerakkan kamera dari website*/ </tr> </table> </div> <? }?></td> </tr> </table></td> <td width="484" align="center" valign="top" bgcolor="#FFFFFF"> <? if (emptyString($_COOKIE[id])){ ?> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr align="center"> <td><a href="open.php"><img src="gambar/g2.jpg" width="60" height="60"></td> <td><a href="video.php"><img src="gambar/g1hidden.jpg" width="60" height="60"></td> <td><a href="viewpict.php"><img src="gambar/g3hidden.jpg" width="60" height="60"></td> <td><a href="viewtrafik.php"><img src="gambar/g4hidden.jpg" width="60" height="60"></td> <td><a href="help.php"><img src="gambar/g5hidden.jpg" width="60" height="60"></td> </tr> <tr align="center" class="teksdua"> <td><a href="open.php">Open Streaming</td> <td><a href="video.php">Video Capture </td> <td><a href="viewpict.php">View Capture </td> <td><a href="viewtrafik.php">View Traffic </td> <td><a href="help.php">Help</td> </tr> </table><? } else {?> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr align="center"> <td><img src="gambar/g2.jpg"></td> <td><a href="video.php"><img src="gambar/g1.jpg" border="0"></a></td> <td><a href="viewpict.php"><img src="gambar/g3.jpg" border="0"></a></td> <td><a href="http://www.10.14.200.2:3001"><img src="gambar/g4.jpg" border="0"></a></td> <td><a href="/help.php"><img src="gambar/g5.jpg" border="0"></a></td> </tr> <tr align="center" class="teksdua"> <td><a href="/open.php">Open Streaming</a></td> <td><a href="/video.php">Video Capture</a> </td> <td><a href="/viewpict.php">View Picture</a> </td> <td><a href="/viewtrafik.php">View Traffic</a> </td> <td><a href="/help.php">Help</a></td> </tr> </table> <? }?> <br><br> and here is my login.php script : <? include "header.php"; switch ($mod){ case "logout" : /*session_unregister($_SESSION[usrnm]); $_SESSION[usrnm] = ""; unset($_SESSION[usrnm]); session_unregister($_SESSION[id]); $_SESSION[id] = ""; unset($_SESSION[id]);*/ setcookie("username",""); setcookie("id",""); message_url("Anda telah logout..Terima kasih atas kunjungannya!!!","/"); break; default : if (emptyString($_POST[usrnm])) message_back('Username belum diisi'); if (emptyString($_POST[psw])) message_back('Password belum diisi'); //cek di table (proses authentifikasi) $pass_md5 = md5($_POST[psw]); $qr = mysql_query("SELECT * FROM stream WHERE username='$_POST[usrnm]' AND password='$pass_md5'"); $loaduser = mysql_fetch_assoc($qr); if (mysql_num_rows($qr) == '1'){ /*Create session session_register("usrnm"); $_SESSION[usrnm]="$loaduser[username]"; session_register("id"); $_SESSION[id]="$loaduser[id]";*/ setcookie("username","$loaduser[username]"); setcookie("id","$loaduser[id]"); message_url("Selamat Datang $loaduser[nama]","/admin.php"); } else { message_back('Username/Password Anda salah... data tidak ditemukan'); } break; } include "footer.php"; ?> This is really killing the functionality of the site.Any help would be greatly appreciated. (edited by kenrbnsn to add tags) Quote Link to comment https://forums.phpfreaks.com/topic/130876-warning-cannot-modify-header-information-headers-already-sent-by/ Share on other sites More sharing options...
Adam Posted October 31, 2008 Share Posted October 31, 2008 setCookie must be sent with the header, ie. before any HTML .. Quote Link to comment https://forums.phpfreaks.com/topic/130876-warning-cannot-modify-header-information-headers-already-sent-by/#findComment-679310 Share on other sites More sharing options...
revraz Posted October 31, 2008 Share Posted October 31, 2008 http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment https://forums.phpfreaks.com/topic/130876-warning-cannot-modify-header-information-headers-already-sent-by/#findComment-679325 Share on other sites More sharing options...
zuko Posted November 2, 2008 Author Share Posted November 2, 2008 my friend had told me that, adam. but i still dont understand what to do (newbie). so.. what should i do with the script? would you mind guiding me with the script? thanks. Quote Link to comment https://forums.phpfreaks.com/topic/130876-warning-cannot-modify-header-information-headers-already-sent-by/#findComment-680557 Share on other sites More sharing options...
Adam Posted November 4, 2008 Share Posted November 4, 2008 what's in header.php? If there's HTML in there you'll need to put that after you process the login .. Quote Link to comment https://forums.phpfreaks.com/topic/130876-warning-cannot-modify-header-information-headers-already-sent-by/#findComment-682158 Share on other sites More sharing options...
zuko Posted November 6, 2008 Author Share Posted November 6, 2008 i've posted my header.php . yes, but the login process always included header.php, i've posted login.php too. where is exactly i put the html ? Quote Link to comment https://forums.phpfreaks.com/topic/130876-warning-cannot-modify-header-information-headers-already-sent-by/#findComment-683708 Share on other sites More sharing options...
mrMarcus Posted November 6, 2008 Share Posted November 6, 2008 try wrapping your page with... <?php session_start(); ob_start(); // everything else... ob_end_flush(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/130876-warning-cannot-modify-header-information-headers-already-sent-by/#findComment-683749 Share on other sites More sharing options...
zuko Posted November 10, 2008 Author Share Posted November 10, 2008 thanks marcus, i'll try Quote Link to comment https://forums.phpfreaks.com/topic/130876-warning-cannot-modify-header-information-headers-already-sent-by/#findComment-686808 Share on other sites More sharing options...
wrathican Posted November 10, 2008 Share Posted November 10, 2008 did you even read the link that revraz posted? it's a stickied topic in this section. please read it, the information in there is invaluable Quote Link to comment https://forums.phpfreaks.com/topic/130876-warning-cannot-modify-header-information-headers-already-sent-by/#findComment-686817 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.