budimir Posted July 2, 2008 Share Posted July 2, 2008 Hey Guys, I'm constantly getting an error message like this: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\wamp\www\erp\admin\servis\pregled.php:1) in C:\wamp\www\erp\admin\servis\include\session.php on line 2 I have checked for the output, whiote spaces, etc. But I couldn't solve the problem. Can someone, please, take a look and tell me what's wrong??? I can't see it! I have attached pregled.php where I'm getting the error message, and I have attached session.php which I include in pregled.php and in which I'm keeping all the data for the session. Please help!!!!! [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/112885-solved-session-problem/ Share on other sites More sharing options...
Lamez Posted July 2, 2008 Share Posted July 2, 2008 move the start session to the very first line of your code, if that does not help check the white space around the opening and closing php tags, and as a last resort at this to the top of your code: ob_start(); Quote Link to comment https://forums.phpfreaks.com/topic/112885-solved-session-problem/#findComment-579829 Share on other sites More sharing options...
budimir Posted July 2, 2008 Author Share Posted July 2, 2008 1.) Start_session is at a first line of code 2.) There is no white spaces in a whole session.php and also no output 3. ) ob_start is not helping What else could be wrong???? Quote Link to comment https://forums.phpfreaks.com/topic/112885-solved-session-problem/#findComment-579831 Share on other sites More sharing options...
MasterACE14 Posted July 2, 2008 Share Posted July 2, 2008 if your including one of those files, within another file, then put session_start() right at the very top after the <?php in the file its included in. Quote Link to comment https://forums.phpfreaks.com/topic/112885-solved-session-problem/#findComment-579832 Share on other sites More sharing options...
budimir Posted July 2, 2008 Author Share Posted July 2, 2008 No, still not working! What the hell....? ??? What else could it be?? When I'm including a file, session_start() is the first line of the included file. There is no output, there is no white spaces but, I'm getting an error message. Could it be that something is preventing session_start() from starting???? Quote Link to comment https://forums.phpfreaks.com/topic/112885-solved-session-problem/#findComment-579856 Share on other sites More sharing options...
budimir Posted July 2, 2008 Author Share Posted July 2, 2008 Ok, so I have done like this... It's a begining of the file where I get an error message: <?php ob_start(); session_start(); $session_id = session_id(); include ("include/db.php"); $upit = "SELECT * FROM korisnici WHERE session_id = '$session_id'"; $rezultat = mysql_query($upit,$veza) or die (mysql_error()); $row = mysql_fetch_array($rezultat); $user_id = $row["id"]; $ime = $row["ime"]; $korisnicko_ime = $row["korisnicko_ime"]; $prezime = $row["prezime"]; $userData["status"] = $row["status"]; $lozinka = $row["lozinka"]; if (!$user_id){ header("Location:../../logout.php"); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style type="text/css"> ..... This is the error message I'm getting: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\wamp\www\erp\admin\servis\pregled.php:1) in C:\wamp\www\erp\admin\servis\pregled.php on line 3 Any ideas???? Quote Link to comment https://forums.phpfreaks.com/topic/112885-solved-session-problem/#findComment-579870 Share on other sites More sharing options...
mmarif4u Posted July 2, 2008 Share Posted July 2, 2008 Can you try like this: <?php session_start(); ob_start(); ........... ?> Quote Link to comment https://forums.phpfreaks.com/topic/112885-solved-session-problem/#findComment-579872 Share on other sites More sharing options...
budimir Posted July 2, 2008 Author Share Posted July 2, 2008 No, not working. This is what happens: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\wamp\www\erp\admin\servis\pregled.php:1) in C:\wamp\www\erp\admin\servis\pregled.php on line 2 Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\erp\admin\servis\pregled.php:1) in C:\wamp\www\erp\admin\servis\pregled.php on line 16 Quote Link to comment https://forums.phpfreaks.com/topic/112885-solved-session-problem/#findComment-579874 Share on other sites More sharing options...
budimir Posted July 2, 2008 Author Share Posted July 2, 2008 An all other pages that file is not making any problems, but on this one it's making big problem. Why???? I tried to edit it once with notepad, and after that I get a problem. Is it connected somehow?? Quote Link to comment https://forums.phpfreaks.com/topic/112885-solved-session-problem/#findComment-579875 Share on other sites More sharing options...
mmarif4u Posted July 2, 2008 Share Posted July 2, 2008 Did u include this page some where else in other scripts. Where is line 16. Quote Link to comment https://forums.phpfreaks.com/topic/112885-solved-session-problem/#findComment-579876 Share on other sites More sharing options...
budimir Posted July 2, 2008 Author Share Posted July 2, 2008 session.php is included in every page on the site. But it's only making a problem on that page. Line 16 is with header: if (!$user_id){ header("Location:../../logout.php"); } Quote Link to comment https://forums.phpfreaks.com/topic/112885-solved-session-problem/#findComment-579878 Share on other sites More sharing options...
budimir Posted July 2, 2008 Author Share Posted July 2, 2008 OK, to make it clearer! Session.php is a file where I keep all of my session info (you can see it beneath): <?php session_start(); ob_start(); $session_id = session_id(); include ("db.php"); $upit = "SELECT * FROM korisnici WHERE session_id = '$session_id'"; $rezultat = mysql_query($upit,$veza) or die (mysql_error()); $row = mysql_fetch_array($rezultat); $user_id = $row["id"]; $ime = $row["ime"]; $korisnicko_ime = $row["korisnicko_ime"]; $prezime = $row["prezime"]; $userData["status"] = $row["status"]; $lozinka = $row["lozinka"]; if (!$user_id){ header "Location:../../logout.php"); } $_SESSION['session_time'] = time(); //got the login time for user in second $session_logout = 2000; //it means 15 minutes. //and then cek the time session if($session_logout >= $_SESSION['session_time']){ //user session time is up //destroy the session session_destroy(); //redirect to login page header("Location:../../../index.php"); } ?> I include it to pregled.php (you can see it beneath): <?php include("include/session.php"); ?> I have checked session.php for: output, white spaces, putted session_start() in a first line... So, what else can I check?? Quote Link to comment https://forums.phpfreaks.com/topic/112885-solved-session-problem/#findComment-579880 Share on other sites More sharing options...
mmarif4u Posted July 2, 2008 Share Posted July 2, 2008 Where you include your session file in this script.i didn't see here. If you include this script in other script and that script have already session.php included.please remove session from this script. hope it will work this way. <?php session_start(); ob_start(); $session_id = session_id(); include ("db.php"); $upit = "SELECT * FROM korisnici WHERE session_id = '$session_id'"; $rezultat = mysql_query($upit,$veza) or die (mysql_error()); $row = mysql_fetch_array($rezultat); $user_id = $row["id"]; $ime = $row["ime"]; $korisnicko_ime = $row["korisnicko_ime"]; $prezime = $row["prezime"]; $userData["status"] = $row["status"]; $lozinka = $row["lozinka"]; if (!$user_id){ header "Location:../../logout.php"); } $_SESSION['session_time'] = time(); //got the login time for user in second $session_logout = 2000; //it means 15 minutes. //and then cek the time session if($session_logout >= $_SESSION['session_time']){ //user session time is up //destroy the session session_destroy(); //redirect to login page header("Location:../../../index.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/112885-solved-session-problem/#findComment-579884 Share on other sites More sharing options...
whiteboikyle Posted July 2, 2008 Share Posted July 2, 2008 I was having alot of those problems to.. but i made a function using javascript and php function header_sent($url){ echo "<script language=JavaScript>self.location.href='./$url'</script>"; } then where you use your header(location) files do this header_sent("URL.php"); bam it works Quote Link to comment https://forums.phpfreaks.com/topic/112885-solved-session-problem/#findComment-579886 Share on other sites More sharing options...
budimir Posted July 2, 2008 Author Share Posted July 2, 2008 OK, I get what you mean! But, it's not header which is making problems. The session_start() is causing a problem. Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\wamp\www\erp\admin\servis\pregled.php:1) in C:\wamp\www\erp\admin\servis\include\session.php on line 2 I don't understand what is keeping the session_start() from starting Quote Link to comment https://forums.phpfreaks.com/topic/112885-solved-session-problem/#findComment-579893 Share on other sites More sharing options...
budimir Posted July 2, 2008 Author Share Posted July 2, 2008 Where you include your session file in this script.i didn't see here. If you include this script in other script and that script have already session.php included.please remove session from this script. hope it will work this way. <?php session_start(); ob_start(); $session_id = session_id(); include ("db.php"); $upit = "SELECT * FROM korisnici WHERE session_id = '$session_id'"; $rezultat = mysql_query($upit,$veza) or die (mysql_error()); $row = mysql_fetch_array($rezultat); $user_id = $row["id"]; $ime = $row["ime"]; $korisnicko_ime = $row["korisnicko_ime"]; $prezime = $row["prezime"]; $userData["status"] = $row["status"]; $lozinka = $row["lozinka"]; if (!$user_id){ header "Location:../../logout.php"); } $_SESSION['session_time'] = time(); //got the login time for user in second $session_logout = 2000; //it means 15 minutes. //and then cek the time session if($session_logout >= $_SESSION['session_time']){ //user session time is up //destroy the session session_destroy(); //redirect to login page header("Location:../../../index.php"); } ?> This is how I include session.php: <?php include("include/session.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/112885-solved-session-problem/#findComment-579894 Share on other sites More sharing options...
budimir Posted July 2, 2008 Author Share Posted July 2, 2008 1.) The pregled.php file: <?php include("include/session.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style type="text/css"> body{ font-size:0.8em; font-family: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif; margin:0px; padding:0px; } img{ border:0px; } thead td{ font-weight:bold; color:#000; background-color:#E2EBED; } td{ padding:2px; } table{ border:1px solid #000; border-collapse: collapse; } h1{ font-size:1.3em; margin-bottom:0px; } table,h1,p,#ads{ margin-left:10px; } #ads{ margin-top:20px; } /* These classes are used by the script as rollover effect for table 1 and 2 */ .tableRollOverEffect1{ background-color:#317082; color:#FFF; } .tableRollOverEffect2{ background-color:#000; color:#FFF; } .tableRowClickEffect1{ background-color:#F00; color:#FFF; } .tableRowClickEffect2{ background-color:#00F; color:#FFF; } </style> <script type="text/javascript"> /************************************************************************************************************ (C) www.dhtmlgoodies.com, November 2005 This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website. Terms of use: You are free to use this script as long as the copyright message is kept intact. However, you may not redistribute, sell or repost it without our permission. Thank you! www.dhtmlgoodies.com Alf Magne Kalleland ************************************************************************************************************/ var arrayOfRolloverClasses = new Array(); var arrayOfClickClasses = new Array(); var activeRow = false; var activeRowClickArray = new Array(); function highlightTableRow() { var tableObj = this.parentNode; if(tableObj.tagName!='TABLE')tableObj = tableObj.parentNode; if(this!=activeRow){ this.setAttribute('origCl',this.className); this.origCl = this.className; } this.className = arrayOfRolloverClasses[tableObj.id]; activeRow = this; } function clickOnTableRow() { var tableObj = this.parentNode; if(tableObj.tagName!='TABLE')tableObj = tableObj.parentNode; if(activeRowClickArray[tableObj.id] && this!=activeRowClickArray[tableObj.id]){ activeRowClickArray[tableObj.id].className=''; } this.className = arrayOfClickClasses[tableObj.id]; activeRowClickArray[tableObj.id] = this; } function resetRowStyle() { var tableObj = this.parentNode; if(tableObj.tagName!='TABLE')tableObj = tableObj.parentNode; if(activeRowClickArray[tableObj.id] && this==activeRowClickArray[tableObj.id]){ this.className = arrayOfClickClasses[tableObj.id]; return; } var origCl = this.getAttribute('origCl'); if(!origCl)origCl = this.origCl; this.className=origCl; } function addTableRolloverEffect(tableId,whichClass,whichClassOnClick) { arrayOfRolloverClasses[tableId] = whichClass; arrayOfClickClasses[tableId] = whichClassOnClick; var tableObj = document.getElementById(tableId); var tBody = tableObj.getElementsByTagName('TBODY'); if(tBody){ var rows = tBody[0].getElementsByTagName('TR'); }else{ var rows = tableObj.getElementsByTagName('TR'); } for(var no=0;no<rows.length;no++){ rows[no].onmouseover = highlightTableRow; rows[no].onmouseout = resetRowStyle; if(whichClassOnClick){ rows[no].onclick = clickOnTableRow; } } } </script> <title>Servisna mreža</title> <link rel="stylesheet" type="text/css" href="style1.css" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> <!-- .style9 {color: #FFFFFF; font-size: 11px; font-weight: bold; } --> </style> </head> <body> <div class="container"> <div class="titleblock"> <br /> <h1>Servisna mreža</h1><p>“Aplikacija za vođenje evidencije o servisima.”</p></div> <div><ul class="navbar"> <li><a href="index.php" class="nav">Servisi</a></li> <li><a href="izvjestaji.php" class="nav">Izvještaji</a></li> <li><a href="popis_servisa_l.php" class="nav">Popis servisa</a></li> <li><a href="naljepnice.php" class="nav">Naljepnice</a></li> <li><a href="poruke/inbox.php" class="nav">Poruke</a></li> <li><a href="../servis/todo.php" class="nav">Taskovi</a></li> </ul></div> <div class="rightcontainer"> <div class="rightbox"> <h2 align="center"><img src="fleche.gif"alt="arrow" /> Najviše posjeta</h2> <?php //Ovdje izvlačim ID najposječenijeg servisa $upit = "SELECT ID,COUNT(*) as highest FROM obilasci GROUP BY ID ORDER BY highest DESC limit 1"; $rezultat = mysql_query($upit,$veza); $broj = mysql_num_rows($rezultat); $i = 0; while ($i<$broj){ $id12 = mysql_result($rezultat,$i,"id"); $highest2 = mysql_result($rezultat,$i,"highest"); echo "Broj obilazaka: <b>$highest2</b>"; $i++; } //Ovdje dobivam ime po ID-u najposječenijeg servisa $upit2 = "SELECT * FROM opcenito where id = '$id12' LIMIT 1"; $rezultat2 = mysql_query($upit2); $broj2 = mysql_num_rows($rezultat2); $i2 = 0; while ($i2<$broj2){ $naziv = mysql_result($rezultat2,$i2,"naziv"); echo "<br/>$naziv"; $i2++; } ?> <h2 align="center"><img src="fleche.gif"alt="arrow" /> Najviše obilazio</h2> <?php $upit = "SELECT * FROM obilasci WHERE upisao = 'Budimir'"; $rezultat = mysql_query($upit,$veza); $broj = mysql_num_rows($rezultat); $upit2 = "SELECT * FROM obilasci WHERE upisao = 'Marijo'"; $rezultat2 = mysql_query($upit2); $broj2 = mysql_num_rows($rezultat2); if ($broj>$broj2){ echo "Budimir - $broj obilaska"; } else { echo "Marijo - $broj2 obilaska"; } ?> <h2><img src="fleche.gif"alt="arrow"/> Pretraživač</h2> <p>Upišite termin koji tražite: </p> <form name="form" action="search.php" method="get"> <input type="text" name="q" /> <input type="submit" name="Submit" value="Traži" /> </form> <h2><img src="fleche.gif"alt="arrow" /> Link</h2> <p><a href="http://server2/" title="Husqvarna.hr">Husqvarna.hr</a><br /> <a href="http://weborder.husqvarna.se/" title="HQ WebOrder">WebOrder</a><br /> <a href="http://support.husqvarna.com/" title="Support Husqvarna">Support-Husqvarna</a><br /> <a href="http://www.support.jonsered.com/" title="Support Jonsered">Support-Jonsered</a><br /> <a href="http://copsupport.husqvarna.com" title="Support-Partner">Support-Partner</a><br /> <a href="http://copsupport.husqvarna.com" title="Support-Flymo">Support-Flymo</a><br /> <a href="http://copsupport.husqvarna.com" title="Support-McCulloch">Support-McCulloch</a><br /> <a href="http://support.automower.com" title="Support-Automower">Support-Automower</a></p> <h2><img src="fleche.gif"alt="arrow" /> Vrijeme i datum</h2> <p> <?php $vrijeme = date("H:i:s"); $datum = date("d.m.Y"); echo "$vrijeme | $datum"; ?> </p> </div> </div> <div class="content"> <p> </p> <table id="myTable" width="1080" height="41" border="0"> <tr> <td width="152" height="15" bgcolor="#CCCCCC"><div align="center" class="style9">Naziv servisa</div></td> <td width="261" bgcolor="#CCCCCC"><div align="center" class="style9">Adresa</div></td> <td width="104" bgcolor="#CCCCCC"><div align="center" class="style9">Grad</div></td> <td width="104" bgcolor="#CCCCCC"><div align="center" class="style9">Telefon</div></td> <td width="113" bgcolor="#CCCCCC"><div align="center" class="style9">Mob</div></td> <td width="170" bgcolor="#CCCCCC"><div align="center" class="style9">Email</div></td> <td width="106" bgcolor="#CCCCCC"><div align="center" class="style9"><u>Opcije</u></div></td> </tr> <?php //Upit na bazu $upit = "SELECT * FROM opcenito WHERE aktivan = 1 ORDER BY naziv ASC"; $rezultat = mysql_query($upit,$veza); $broj = mysql_num_rows($rezultat); $i=0; while ($i < $broj) { $id = mysql_result($rezultat,$i,"id"); $ime = mysql_result($rezultat,$i,"ime"); $prezime = mysql_result($rezultat,$i,"prezime"); $naziv = mysql_result($rezultat,$i,"naziv"); $mb = mysql_result($rezultat,$i,"mb"); $adresa = mysql_result($rezultat,$i,"adresa"); $adresa1 = mysql_result($rezultat,$i,"adresa1"); $ptt = mysql_result($rezultat,$i,"ptt"); $grad = mysql_result($rezultat,$i,"grad"); $zupanija = mysql_result($rezultat,$i,"zupanija"); $sifra = mysql_result($rezultat,$i,"sifra"); $email1 = mysql_result($rezultat,$i,"email1"); $telefon = mysql_result($rezultat,$i,"telefon"); $telefon1 = mysql_result($rezultat,$i,"telefon1"); $fax = mysql_result($rezultat,$i,"fax"); $mob = mysql_result($rezultat,$i,"mob"); $mob1 = mysql_result($rezultat,$i,"mob1"); $email = mysql_result($rezultat,$i,"email"); $web = mysql_result($rezultat,$i,"web"); $napomena = mysql_result($rezultat,$i,"napomena"); $os = mysql_result($rezultat,$i,"os"); $sos = mysql_result($rezultat,$i,"sos"); $soc = mysql_result($rezultat,$i,"soc"); ?> <tr> <script type="text/javascript"> function provjera(href){ var odgovor = confirm('Jeste li sigurni da želite obrisati sve podatke o servisu?'); return odgovor ? window.location = href : false; } </script> <td height="20" class="donja"><?php echo '<a href="detalji.php?id='.$id.'">'?> <?php echo "$naziv"; ?></td> <td class="donja"><?php echo "$adresa"; ?></td> <td class="donja"><?php echo "$grad"; ?></td> <td align="center" class="donja"><?php echo "$telefon"; ?></td> <td align="center" class="donja"><?php echo "$mob"; ?></td> <td class="donja"><?php echo "$email"; ?></td> <td align="center" class="donja"><?php if ($userData["status"] == 3){ echo '<a href="obrisi.php?id='.$id.'" onclick="provjera(this.href); return false;">Obriši</a>';} else { echo "";}?> <?php if ($userData["status"] == 3) { echo '<a href="izmjeni.php?id='.$id.'">Izmjeni</a>'; } else { echo ""; }?></a></td> </tr> <?php $i++; } ?> </table> <hr /> <div align="right"> <?php //Brojanje aktivnih servisa $upit2 = "SELECT * FROM opcenito WHERE aktivan = 1"; $rezultat2 = mysql_query($upit2,$veza); $broj2 = mysql_num_rows($rezultat2); //Brojanje neaktivnih servisa $upit3 = "SELECT * FROM opcenito WHERE aktivan = 0"; $rezultat3 = mysql_query($upit3,$veza); $broj3 = mysql_num_rows($rezultat3); ?> <td><?php echo "Broj aktivnih servisa = $broj2";?></td><br /> <td><?php echo "Broj nekativnih servisa = $broj3";?></td><br /> <td><b><?php echo "Ukupni broj servisa u bazi = $broj";?></b></td> </div> <br /> </div> <script type="text/javascript"> addTableRolloverEffect('myTable','tableRollOverEffect1','tableRowClickEffect1'); addTableRolloverEffect('myTable2','tableRollOverEffect2','tableRowClickEffect2'); </script> <div class="footer"> <div class="right"> <p><?php include ("include/footer.php");?></p> </div> </div> <?php mysql_close($veza);?> </div> </body> </html> 2.) The session.php file: <?php session_start(); $session_id = session_id(); include ("db.php"); $upit = "SELECT * FROM korisnici WHERE session_id = '$session_id'"; $rezultat = mysql_query($upit,$veza) or die (mysql_error()); $row = mysql_fetch_array($rezultat); $user_id = $row["id"]; $ime = $row["ime"]; $korisnicko_ime = $row["korisnicko_ime"]; $prezime = $row["prezime"]; $userData["status"] = $row["status"]; $lozinka = $row["lozinka"]; if (!$user_id){ header ("Location:../../logout.php"); } $_SESSION['session_time'] = time(); //got the login time for user in second $session_logout = 2000; //it means 15 minutes. //and then cek the time session if($session_logout >= $_SESSION['session_time']){ //user session time is up //destroy the session session_destroy(); //redirect to login page header("Location:../../../index.php"); } ?> The error message on the file: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\wamp\www\erp\admin\servis\pregled.php:1) in C:\wamp\www\erp\admin\servis\include\session.php on line 2 Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\erp\admin\servis\pregled.php:1) in C:\wamp\www\erp\admin\servis\include\session.php on line 16 Quote Link to comment https://forums.phpfreaks.com/topic/112885-solved-session-problem/#findComment-579899 Share on other sites More sharing options...
whiteboikyle Posted July 2, 2008 Share Posted July 2, 2008 uhmm do @session_start(); or put it inside the <head></head> Quote Link to comment https://forums.phpfreaks.com/topic/112885-solved-session-problem/#findComment-579904 Share on other sites More sharing options...
budimir Posted July 2, 2008 Author Share Posted July 2, 2008 No, still the same! Quote Link to comment https://forums.phpfreaks.com/topic/112885-solved-session-problem/#findComment-579911 Share on other sites More sharing options...
PFMaBiSmAd Posted July 2, 2008 Share Posted July 2, 2008 When the error refers to output started at line 1, there are two possible causes. There is actual content (characters, space, tab, newline) before the <?php tag OR the file is saved in UTF-8 format and the BOM (byte order mark) characters at the start of the file are being output to the browser. Assuming you have already checked for any actual content in the file before the <?php tag, make sure your file is saved in ANSI/ASCII mode or if you must save it as UTF-8, use an editor that allows you to save it without the BOM. Quote Link to comment https://forums.phpfreaks.com/topic/112885-solved-session-problem/#findComment-579940 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.