Current location: Hot Scripts Forums » Programming Languages » PHP » sessions writing to mysql report errors


sessions writing to mysql report errors

Reply
  #1 (permalink)  
Old 08-30-05, 07:34 AM
perleo perleo is offline
Coding Addict
 
Join Date: Jul 2003
Location: Ireland
Posts: 269
Thanks: 0
Thanked 0 Times in 0 Posts
sessions writing to mysql report errors

Hi

I get these errors:

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /var/www/board.php:1) in /var/www/sessions.php on line 116

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /var/www/board.php:1) in /var/www/sessions.php on line 116

Fatal error: Call to a member function on a non-object in /var/www/sessions.php on line 57

Warning: Unknown(): A session is active. You cannot change the session module's ini settings at this time. in Unknown on line 0

Heres my code

PHP Code:

 $session_life get_cfg_var("session.gc_maxlifetime");


  
//function to open our session
  
function session_open$save_path$session_name )
   {
      return 
true;
   }

   
//function to close our session
   
function session_close()
    {
       return 
true;
    }

    
//function to read the value of a session variable
    
function session_read$sessid )
     {
        global 
$DBI;

        
$query_string "SELECT data FROM diet_sessions WHERE sessionID = '$sessid' AND expires > ".time();

        
//run the query
        
$query $DBI->query$query_string ); //LINE 57

        
$result $query->fetchRows();

        if( 
$result )
         {
           return 
$result->data;
         }

         return 
false;
     }

     
//function to write session variables to the DB table
     
function session_write$sessid$value )
      {
         global 
$session_life$DBI;

         
$expire_time time()+$session_life;

         
$values addslashes$value );
 
//check that this session doesnt already exist
         
$check_query_string "SELECT * FROM diet_sessions WHERE sessionID = '

         
$check_result = $DBI->query$check_query_string );

         
$check_num = $check_result->numRows();

         if( 
$check_num >= '1' )
          {
            
$update_string = "UPDATE diet_sessions SET expires '$expire_time'
                             "WHERE sessionID = '
$sessid' AND expires > ".time(

            
$update_query $DBI->query$update_string );

          }
          elseif( 
$check_num <= '0' )
          {
 
$insert_string "INSERT INTO diet_sessions VALUES ('$sessid', '$ex

            
$insert_query = $DBI->query$insert_string );

          }

          return 
$insert_query;
      }

      //function to destroy our session
      function session_end( 
$sessid )
       {
          global 
$DBI;

          
$query_string = "DELETE FROM diet_sessions WHERE sessionID '$sessid

          $query = $DBI->query( $query_string );

          return $query;

       }
  function session_gc( $maxlifetime )
        {
           global $DBI;

           $query_string = "DELETE FROM diet_sessions WHERE expires < ".time();

           $query = $DBI->query( $query_string );

           return 1;

        }

        //setup PHP'
s session handler to use our functions instead of the defau
        session_set_save_handler
"session_open",
                                  
"session_close",
                                  
"session_read",
                                  
"session_write",
                                  
"session_end",
                                  
"session_gc");

        
//finally, startup our session
        
session_start();

?> 
my $DBI is a class which is in called in the include.php file.

The $DBI class works, iam certain, but i dont know why the sessions file gives out, and why cant I send out the session_start();
I know its supposed to be at the stop of every script, but in this case as iam writing my owne session functions, it shouldnt matter??
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 08-30-05, 08:15 AM
darkfreak's Avatar
darkfreak darkfreak is offline
Newbie Coder
 
Join Date: Jun 2004
Location: Kuopio, Finland, Europe
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
Try to change this:
PHP Code:

            $update_string "UPDATE diet_sessions SET expires = '$expire_time
                             "
WHERE sessionID '$sessid' AND expires ".time( 
to this (remove that quotemark before WHERE):
PHP Code:

            $update_string "UPDATE diet_sessions SET expires = '$expire_time
                              WHERE sessionID = '
$sessid' AND expires > ".time
Any help?

edit: nevermind, your whole code seems to be cut from the right...

Last edited by darkfreak; 08-30-05 at 08:19 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 08-30-05, 08:29 AM
perleo perleo is offline
Coding Addict
 
Join Date: Jul 2003
Location: Ireland
Posts: 269
Thanks: 0
Thanked 0 Times in 0 Posts
no difference
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 08-30-05, 09:33 AM
ranbla ranbla is offline
Newbie Coder
 
Join Date: Aug 2005
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
You've got some string termination issues on your query strings. You're including code in your query strings because they are not terminated properly with closing quotes.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 08-30-05, 11:25 AM
perleo perleo is offline
Coding Addict
 
Join Date: Jul 2003
Location: Ireland
Posts: 269
Thanks: 0
Thanked 0 Times in 0 Posts
but if at the top of the script I do

PHP Code:

$query $DBI->query"SELECT * FROM table" ); 

it returns the same type of error,


Fatal error: Call to a member function on a non-object in /var/www/sessions.php on line 35

is it the way I call the database script that has the DBI class ?

I do $DBI = new DBI( "mysql://root***@localhost/db" );

at the end of the database script. and then include that in the sessions.php
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 08-30-05, 03:33 PM
ranbla ranbla is offline
Newbie Coder
 
Join Date: Aug 2005
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by perleo
is it the way I call the database script that has the DBI class ?

I do $DBI = new DBI( "mysql://root***@localhost/db" );

at the end of the database script. and then include that in the sessions.php
It's very likely that this is the root of your problem. Not knowing what parameters your class constructor is expecting makes it impossible for me to say for sure. I will say it looks very strange tho.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 03:22 AM
mysql search monthly report iconsis PHP 2 07-18-05 02:13 PM
MySQL errors, php, etc... Help Jason B PHP 6 07-23-04 01:14 AM
Disable form fields to be submitted RickyRod JavaScript 2 05-24-04 11:15 AM
MySQL - max_packet_allowed errors mband2000 PHP 0 01-09-04 04:31 AM


All times are GMT -5. The time now is 09:01 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.