Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7651517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:31:38+00:00 2026-05-31T11:31:38+00:00

I have a file sess_function.php This file lists the various (6) functions used to

  • 0

I have a file sess_function.php

This file lists the various (6) functions used to control sessions..

function _open()
{
    try{
        // Open the database
        $dbh = new PDO("mysql:host=$host;dbname=$dbname",$user,$pass);
        $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );  
    } //try
    catch(PDOException $e){
        echo "Oops, We're experiencing an error CONNECTING.";
        file_put_contents('PDODBConnectionErrors.txt', $e->getMessage(), FILE_APPEND);  
    } //catch
}   

## Kill Connection to Mysql (Using PDO) 
function _close(){
$dbh = null;
}

## Read a current session 
function _read($id){
    try{
        // Open the database
        $dbh = new PDO("mysql:host=$host;dbname=$dbname",$user,$pass);
        $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );  
        // Begin Query
        $id = mysql_real_escape_string($id);
        $sth = $dbh->prepare("SELECT data FROM sessions WHERE id = '$id'");
        $sth->execute();

    }
    catch(PDOException $e){
        echo "Oops, We're experiencing an error. READING";
        file_put_contents('PDODBConnectionErrors.txt', $e->getMessage(), FILE_APPEND);  
    } //catch

    ## return '';
}

## Write to current session 
function _write($id, $data){
    // WRITE Vars
    try{
        // Open the database
##      require_once('dbi.php');
        $dbh = new PDO("mysql:host=$host;dbname=$dbname",$user,$pass);
        $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );  
        // Begin Query
        $access = time();
        $id = mysql_real_escape_string($id);
        $access = mysql_real_escape_string($access);
        $data = mysql_real_escape_string($data);
        $sth = $dbh->prepare("REPLACE INTO sessions VALUES ('$id', '$access', '$data')");
        $sth->execute();
    }
    catch(PDOException $e){
        echo "Oops, We're experiencing an error. REPLACING SESSION VAL";
        file_put_contents('PDODBConnectionErrors.txt', $e->getMessage(), FILE_APPEND);  
    } //catch

}

## Destroy current session
function _destroy($id){   
    try{
        // Open the database
##      require_once('dbi.php');
        $dbh = new PDO("mysql:host=$host;dbname=$dbname",$user,$pass);
        $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );  
        // Begin Query
        $id = mysql_real_escape_string($id);
        $sth = $dbh->prepare("DELETE FROM sessions WHERE id = '$id'");
        $sth->execute();
    }
    catch(PDOException $e){
        echo "Oops, We're experiencing an error.";
        file_put_contents('PDODBConnectionErrors.txt', $e->getMessage(), FILE_APPEND);  
    } //catch  
}

## Clean old session data out 
function _clean($max){
    try{
        // Open the database
##      require_once('dbi.php');
        $dbh = new PDO("mysql:host=$host;dbname=$dbname",$user,$pass);
        $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );  
        // Begin Query
        $old = time() - $max;
        $old = mysql_real_escape_string($old);
        $sth = $dbh->prepare("DELETE FROM sessions WHERE  access < '$old'");
        $sth->execute();
    }
    catch(PDOException $e){
        echo "Oops, We're experiencing an error. DEL FROM SESSION";
        file_put_contents('PDODBConnectionErrors.txt', $e->getMessage(), FILE_APPEND);  
    } //catch

}

and index.php

////////////////////////////////////////////////////////////////////////////////////
###### Require Database ######                              ////////////////////////
####### DB Config Setting #######
$host ='localhost'; //////////////
$dbname ='mydb';//////////
$user ='root';     //////////////
$pass ='';         //////////////
/////////////////////////////////


                        ////////////////////////
////////////////////////////////////////////////////////////////////////////////////
###### Start session                                        ////////////////////////
session_start();                                            ////////////////////////
###### Call Session Functions Include ######                ////////////////////////            
require_once('src/cfg/sess_function.php');                  ////////////////////////
###### Call function as contained in sess_function() ######                       //
session_set_save_handler('_open','_close','_read','_write','_destroy','_clean');  //                            
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////

The table looks like:
img1

The problem is: it gives me no problem, but nothing is stored in the sessions table…

if I UNCOMMENT session_start(); it throws these warnings:

Oops, We're experiencing an error. READING
Warning: session_start() Cannot send session cookie - headers already sent by sess_function.php:33)index.php on line 12

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started sess_function.php:33) in index.php on line 12

Anyone??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:31:40+00:00Added an answer on May 31, 2026 at 11:31 am

    The first error message is what you should be looking at. PHP needs to send HTTP header data (a cookie), but there’s already been some output in sess_function.php. Header data cannot be sent after regular output (say, echo). You print “Oops, We’re experiencing an error. READING”, which is the output PHP complains about. Removing all echo statements will resolve the session problem.

    Then: the $dbname, $user, $pass and $host variables weren’t set. global $dbname, $host, $user, $pass; declarations fixed that.

    Finally: session_set_save_handler must be called before session_start, because otherwise PHP won’t call the custom functions. The output already sent errors happened because the MySQL errors were triggered before session_start finished running (the MySQL errors occured during session_start)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file foo.bar.1 on my server and when I try to access
I have file where each line is json string. I load this file to
I have file which looks like this: >gi|358482566|ref|NW_003766328.1| Gallus gallus breed Red Jungle fowl,
I have file which contains some data, like this 2011-01-02 100100 1 2011-01-02 100200
I have file that consists various Unicode characters. I want to convert all those
I have file with this specific format: 0 2 4 0 1 A 0
i have file called data_out.xml which contains this xml code: <?xml version=1.0 ?> -
I have file that I need to hash, this file can be too large
I have file called denem.txt and has content 123456789 123456789 123456789 When we open
I have file with jspx extension i write javascript like function isNumber(inputId){ var value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.