Jump to content

[SOLVED] Session headers error


conker87

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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;
    }
?>

Link to comment
Share on other sites

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 :P

 

 

Regards

Liam

Link to comment
Share on other sites

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;
    }
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.