mark103 Posted April 9, 2013 Share Posted April 9, 2013 Hi guys,I need your help. I got a problem with my php script where i cannot ignore the warning: session_start. The warning I get is: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/myusername/public_html/test.php:6) in /home/myusername/public_html/test.php on line 7 <html> <body> <table> <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'myusername'); define('DB_PASSWORD', 'mypassword'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $qrytable1="SELECT id, channels FROM tvguide"; $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); while ($row = mysql_fetch_array($result1)) { echo "<tr><td>".$row['channels']."</td></tr>"; } } ?> </table> </html> Does anyone know what the trouble is and how to remove the warning session_start?thanks in advance Quote Link to comment Share on other sites More sharing options...
Strider64 Posted April 9, 2013 Share Posted April 9, 2013 (edited) What I do is have a common.php at the top of my page before my header info like this: <?php require_once("includes/common.php"); ?> <?php require("includes/Thread.Reply.Class.php"); ?> <?php $dynamic_menu = new ThreadReplayClass; // Instances for Displays Threads and Replies $threads = $dynamic_menu->display_topic(); $user_comments = $dynamic_menu->display_replies(); ?> <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> Then in my common.php file I do this <?php define('DB_HOST', 'localhost'); define('DB_USERNAME', 'root'); define('DB_PASSWORD', '*******'); define('DB_NAME', 'your_database'); header('Content-Type: text/html; charset=utf-8'); session_start(); This prevents a lot of those errors from happening in the first place, but you still have to be careful on a few other gotchas. Edited April 9, 2013 by Strider64 Quote Link to comment Share on other sites More sharing options...
jcbones Posted April 9, 2013 Share Posted April 9, 2013 Anything that writes to the screen is output. You can have NO output before a session_start() call, or a header() call. Quote Link to comment 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.