conker87 Posted September 30, 2007 Share Posted September 30, 2007 I've been adding and coding several pages before the following suddenly appeared at the top of my index page: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/conker87/public_html/index.php:1) in /home/conker87/public_html/_var.php on line 12 Which would be all well and good, but the settings page is required(); BEFORE even the <html> tag and there are NO headers at all sent before this tag. The, apparent, offending line is: ini_set("session.gc_maxlifetime", "43200"); // Set the session life to 12 hours. ... if(!isset($_SESSION)) { session_start(); } // Starts the session if a Session is not in progress. <------- I have changed absolutely nothing of the section of the variable file nor done anything to the top of the index page where this is showing. It just started showing up about an hour ago. Anyone got any ideas as to what is causing this? I have changed editors in the last hour, but I'm sure that's not it. Quote Link to comment Share on other sites More sharing options...
Orio Posted September 30, 2007 Share Posted September 30, 2007 Can you show the first 15 lines? Orio. Quote Link to comment Share on other sites More sharing options...
conker87 Posted September 30, 2007 Author Share Posted September 30, 2007 Going to assume you meant the settings page, here it is: <?php // ************************ // * General Var * // ************************ //ini_set("session.gc_maxlifetime", "43200"); // Set the session life to 12 hours. // ************************ // * Session * // ************************ if(!isset($_SESSION)) { session_start(); } // Starts the session if a Session is not in progress. // ************************ // * Include Vars * // ************************ $getid = is_numeric($_GET['id']); ?> Below this is just MySQL data. Quote Link to comment Share on other sites More sharing options...
Orio Posted September 30, 2007 Share Posted September 30, 2007 Make sure you don't have any spaces before the opening <?php. By that I mean no white-spaces or line breaks and of course no html. Orio. Quote Link to comment Share on other sites More sharing options...
conker87 Posted September 30, 2007 Author Share Posted September 30, 2007 This is the top of the html file: <?php require("_var.php"); ?> <html> <head> <link rel="stylesheet" type="text/css" href="_menu.css" /> <link rel="stylesheet" type="text/css" href="_style.css" /> </head> <body> Nothing at all there Quote Link to comment Share on other sites More sharing options...
Orio Posted September 30, 2007 Share Posted September 30, 2007 You can't have any output before calling session_start(). No html either. Orio. Quote Link to comment Share on other sites More sharing options...
conker87 Posted September 30, 2007 Author Share Posted September 30, 2007 There isn't anything before that. Not on the html page, nor on the settings page except the ini_set to change the session duration slightly. Could it be anything to do with that I've switched to Web expression from Frontpage? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 30, 2007 Share Posted September 30, 2007 add ob_start(); to the beggining this should fix it Quote Link to comment Share on other sites More sharing options...
Orio Posted September 30, 2007 Share Posted September 30, 2007 @darkfreaks- thats not a "clean" way to solve this.... Bahh I am confused. Open the source code of the page that gives you the error and tell me if there's anything before the errors please. html, spaces or whatever. Orio. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 30, 2007 Share Posted September 30, 2007 the best way it to eliminate all code before session_start(); Quote Link to comment Share on other sites More sharing options...
shocker-z Posted September 30, 2007 Share Posted September 30, 2007 i would say create a new page called test.php with the following code <?php require("_var.php"); ?> if you still receive the issue then change that code to <?php if(!isset($_SESSION)) { session_start(); } ?> still same error? if so then i'll be damned if not then issue with your required file or origonal page you require this from. Regards Liam Quote Link to comment Share on other sites More sharing options...
conker87 Posted September 30, 2007 Author Share Posted September 30, 2007 @Orio This is the SC: <br /> <b>Warning</b>: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/conker87/public_html/index.php:1) in <b>/home/conker87/public_html/_var.php</b> on line <b>12</b><br /> Just a <br /> before. @shocker-z I created a fire with just <?php require("_var.php"); ?> and same issue, then the same with <?php if(!isset($_SESSION)) { session_start(); } ?> with STILL the same issue. Quote Link to comment Share on other sites More sharing options...
Orio Posted September 30, 2007 Share Posted September 30, 2007 Make sure the in _var.php there are not white spaces or anything before the opening <?php or after the closing ?>. Even one line break can make this problems, this happened to me alot in the past. Orio. Quote Link to comment Share on other sites More sharing options...
shocker-z Posted September 30, 2007 Share Posted September 30, 2007 sounds like you maye have a header set in your ini file or somthing then or a frameset around the page your testing.. your not testing using a free url are you? e.g. test.goto.com or somthing which puts it inside a frame or cloaks the address? Liam Quote Link to comment Share on other sites More sharing options...
conker87 Posted September 30, 2007 Author Share Posted September 30, 2007 Nope, my testing is on my domain. There are no headers being set in _var.php, it's just the above code, some table definitions, MySQL data and some functions at the bottom. I can't see, nor can I find any whitespace before or after either set of <?php ?> tags. Even tried editing the file in notepad seeing if FP or WE was adding spaces. Nothing. Edit: On a side note, could this be anything to do with the servers? It seems like the website of the host I'm on is down. So maybe the servers are acting up? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 30, 2007 Share Posted September 30, 2007 you should really try ob_start(); you wont know until you try it Quote Link to comment Share on other sites More sharing options...
conker87 Posted September 30, 2007 Author Share Posted September 30, 2007 I have Sorry, I didn't mention that, but I've put ob_start(); at the start of _var.php and it still happens. Quote Link to comment Share on other sites More sharing options...
teng84 Posted September 30, 2007 Share Posted September 30, 2007 why use that ob_start()???? you can have your code run even without that if you design it in better way! Quote Link to comment Share on other sites More sharing options...
teng84 Posted September 30, 2007 Share Posted September 30, 2007 can you show this page? require("_var.php"); Quote Link to comment Share on other sites More sharing options...
conker87 Posted September 30, 2007 Author Share Posted September 30, 2007 OK, here is the entire _var.php: <?php ob_start(); // Added to try and recify some stupid session bug that arose. // ************************ // * General Var * // ************************ //ini_set("session.gc_maxlifetime", "43200"); // Set the session life to 12 hours. // ************************ // * Session * // ************************ if(!isset($_SESSION)) { session_start(); } // Starts the session if a Session is not in progress. // ************************ // * Include Vars * // ************************ $getid = is_numeric($_GET['id']); // ************************ // * MySQL * // ************************ // ************************ // * Item Tables * // ************************ define("ARTICLE_TBL","`articles`"); define("ENEMY_TBL","`enemies`"); define("MUSICVIDEO_TBL","`musicvideos`"); define("REVIEW_TBL","`reviews`"); define("STRIP_TLB","`strips`"); define("VIDEO_TBL","`videos`"); // ************************ // * Member Table * // ************************ define("MEMBER_TBL","`members`"); // ************************ // * Other Tables * // ************************ define("SHOUTBOX_TBL","`shoutbox`"); define("COMMENT_TBL","`comment`"); // ************************ // * Database Stuff * // ************************ $host = "X"; // Host. $username = "X"; // Username. $password = "X"; // Password. $database = "X"; // Database. mysql_connect($host, $username, $password) or die("Could not connect to host:<br>" . mysql_error()); // Connect to MySQL server. mysql_select_db($database) or die("Could not connect to database:<br>" . mysql_error()); // Connect to MySQL database. // ************************ // * Functions * // ************************ function explode_tolist($string) { $string = explode(",", $string); echo '<ul>'; foreach ($string as $key => $val) { echo '<li>'.trim($val).'</li>'; } echo '</ul>'; } function strip_br($variable) // Function to remove the <br /> in edits, this keeps the new lines. { return str_replace(array("<br>", "<br />"), "", $variable); } function strip_tags_content($variable) // Function to remove all tags except specified for content fields. { return strip_tags($variable, "<a><b><br><font><hr><i><img><p><span><sub><sup><u>"); } function strip_tags_comment($variable) // Function to remove all tags except specified for comment fields. { return strip_tags($variable, "<a><b><br><i><u>"); } function itemSnippit($variable) // Function to show only 100 characters, used for Reviews and Articles. { return substr(strip_tags($variable), 0, 100) . "..."; } function encrypt($string) // Function to encrypt password with own encryption. { return md5(sha1(sha1(md5($string)))); } function titleCase($string) // Function to set title fields as title case, NOT suitable for usernames. { return ucwords(strtolower($string)); } function removeWordQuotes($string) // Function to remove fucked up quotes and aposhtraphies from forms. { str_replace(array("‘", "’"), "'", str_replace(array("“", "”"), "\"", str_replace("…", "...", $string))); return $string; } function loveLogged() // Function to determine if the sessioned variables are correct, and therefore logged in. { $check = mysql_num_rows(mysql_query("SELECT * FROM ". MEMBER_TBL ." WHERE `username` = '".$_SESSION['username']."' AND `password` ='".$_SESSION['password']."'")); if ($check == 0) { return false; } else if ($check == 1) { return true; } else if ($check > 1) { return false; } } function gmtime() // Function to return the greenich mean time. { $sign = "+"; $h = "0"; $dst = "true"; if ($dst) { $daylight_saving = date('I'); if ($daylight_saving) { if ($sign == "-") { $h=$h-1; } else { $h=$h+1; } } } $hm = $h * 60; $ms = $hm * 60; if ($sign == "-") { $timestamp = time()-($ms); } else { $timestamp = time()+($ms); } $gmdate = gmdate("l jS F\, H:i", $timestamp); return $gmdate; } ?> Quote Link to comment Share on other sites More sharing options...
teng84 Posted September 30, 2007 Share Posted September 30, 2007 basically this is wrong if(!isset($_SESSION)) { session_start(); } // Starts the session if a Session is not in progress. your session will always be empty unless you declare session start Quote Link to comment Share on other sites More sharing options...
shocker-z Posted September 30, 2007 Share Posted September 30, 2007 just curiouse try this.. change if(!isset($_SESSION)) { session_start(); } to session_start(); i say this as you need to start sessions on every poage anyway so it will never be set if isession_start(); has not been called! I think that this may be causing an error in the if(!isset(... and giving out error message therefore causing it di die on session_start(). teng84: beat me to it - as the girlfriend says.. comming first dont always mean your the winner Regards Liam Quote Link to comment Share on other sites More sharing options...
teng84 Posted September 30, 2007 Share Posted September 30, 2007 simply <?php session_start(); // ************************ // * General Var * // ************************ //ini_set("session.gc_maxlifetime", "43200"); // Set the session life to 12 hours. // ************************ // * Session * // ************************ // ************************ // * Include Vars * // ************************ $getid = is_numeric($_GET['id']); // ************************ // * MySQL * // ************************ // ************************ // * Item Tables * // ************************ define("ARTICLE_TBL","`articles`"); define("ENEMY_TBL","`enemies`"); define("MUSICVIDEO_TBL","`musicvideos`"); define("REVIEW_TBL","`reviews`"); define("STRIP_TLB","`strips`"); define("VIDEO_TBL","`videos`"); // ************************ // * Member Table * // ************************ define("MEMBER_TBL","`members`"); // ************************ // * Other Tables * // ************************ define("SHOUTBOX_TBL","`shoutbox`"); define("COMMENT_TBL","`comment`"); // ************************ // * Database Stuff * // ************************ $host = "X"; // Host. $username = "X"; // Username. $password = "X"; // Password. $database = "X"; // Database. mysql_connect($host, $username, $password) or die("Could not connect to host:<br>" . mysql_error()); // Connect to MySQL server. mysql_select_db($database) or die("Could not connect to database:<br>" . mysql_error()); // Connect to MySQL database. // ************************ // * Functions * // ************************ function explode_tolist($string) { $string = explode(",", $string); echo '<ul>'; foreach ($string as $key => $val) { echo '<li>'.trim($val).'</li>'; } echo '</ul>'; } function strip_br($variable) // Function to remove the <br /> in edits, this keeps the new lines. { return str_replace(array("<br>", "<br />"), "", $variable); } function strip_tags_content($variable) // Function to remove all tags except specified for content fields. { return strip_tags($variable, "<a><b><br><font><hr><i><img><p><span><sub><sup><u>"); } function strip_tags_comment($variable) // Function to remove all tags except specified for comment fields. { return strip_tags($variable, "<a><b><br><i><u>"); } function itemSnippit($variable) // Function to show only 100 characters, used for Reviews and Articles. { return substr(strip_tags($variable), 0, 100) . "..."; } function encrypt($string) // Function to encrypt password with own encryption. { return md5(sha1(sha1(md5($string)))); } function titleCase($string) // Function to set title fields as title case, NOT suitable for usernames. { return ucwords(strtolower($string)); } function removeWordQuotes($string) // Function to remove fucked up quotes and aposhtraphies from forms. { str_replace(array("‘", "’"), "'", str_replace(array("“", "”"), "\"", str_replace("…", "...", $string))); return $string; } function loveLogged() // Function to determine if the sessioned variables are correct, and therefore logged in. { $check = mysql_num_rows(mysql_query("SELECT * FROM ". MEMBER_TBL ." WHERE `username` = '".$_SESSION['username']."' AND `password` ='".$_SESSION['password']."'")); if ($check == 0) { return false; } else if ($check == 1) { return true; } else if ($check > 1) { return false; } } function gmtime() // Function to return the greenich mean time. { $sign = "+"; $h = "0"; $dst = "true"; if ($dst) { $daylight_saving = date('I'); if ($daylight_saving) { if ($sign == "-") { $h=$h-1; } else { $h=$h+1; } } } $hm = $h * 60; $ms = $hm * 60; if ($sign == "-") { $timestamp = time()-($ms); } else { $timestamp = time()+($ms); } $gmdate = gmdate("l jS F\, H:i", $timestamp); return $gmdate; } ?> Quote Link to comment Share on other sites More sharing options...
conker87 Posted September 30, 2007 Author Share Posted September 30, 2007 Nope, did that teng84 and it still happens. Quote Link to comment Share on other sites More sharing options...
shocker-z Posted September 30, 2007 Share Posted September 30, 2007 ok then.. create a page called test.php and just have this code in it <?php start_session(); ?> what happens? done require it or anything just go straight to it. if you get the same then remove start_session(); and visit the page anmd look at the source HTML output form the page.. what shows up? There has to be somthing! Liam 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.