"Ghost Sessions" Being Created

I don’t know what’s going on here, on this computer (64bit Win8), running the 32bit WAMP I’m suddenly getting PHP create a new session for each page request as well as the “proper” session. There’s no windows updates outstanding, I’ve been using the 32bit version of PHP as it’s supposed to be.

On another page when testing something it’s inserting more then one record into a table when only one insert was sent. It’s nothing to do with transactions as I’ve disabled all transactions.

Could any recent windows update be causing the strange behaviour?

database sessions class

    <?php

/**
 * Universal Empires
 *
 * Session (Database) Handler Class
 *
 * http://localhost/universal_empires
 *
 * @package SpaceCoreCCMS
 * @author SpacePhoenix
 * @version 1.0
 * @copyright 2012 SpacePhoenix
 */

class db_session_handler implements SessionHandlerInterface {
    
    public function __construct($db) {
        $this->db = $db;
        session_set_save_handler($this);
        session_start();
    }
    
    public function open($save_path,$session_name) {
        $this->db;
        return true;
    }
    
    public function close() {
        unset($this->db);
        return true;
    }
    
    public function read($session_id) {
        try {
            $sql="
                SELECT
                    sess_data
                FROM
                    ue_user_session
                WHERE
                    sess_id = :sess_id
            ";
            $stmt = $this->db->prepare($sql);
            $stmt->bindParam(':sess_id', $session_id);
            $stmt->execute();
            $res = $stmt->fetchAll(PDO::FETCH_ASSOC);
            if (count($res) <> 1 ) {
                return false;
            } else {
                return $res[0]['sess_data'];
            }
        }
        catch (PDOException $e) {
            error_log('Error reading the session data table in the session reading method.',3,"C:\wamp\www\universal_empires\test_log.txt");
            error_log(" Query with error: $sql",3,"C:\wamp\www\universal_empires\test_log.txt");
            error_log(" Reason given: $e->getMessage()",3,"C:\wamp\www\universal_empires\test_log.txt");
            return false;
        }
    }

    public function write($session_id,$session_data) {        
        try {
            $sql="
                SELECT
                    sess_data
                FROM
                    ue_user_session
                WHERE
                    sess_id = :sess_id
            ";
            $stmt = $this->db->prepare($sql);
            $stmt->bindParam(':sess_id', $session_id);
            $stmt->execute();
            $res = $stmt->fetchAll(PDO::FETCH_ASSOC);
        }
        catch (PDOException $e) {
            error_log('Error reading the session data table in the session reading method.',3,"C:\wamp\www\universal_empires\test_log.txt");
            error_log(" Query with error: $sql",3,"C:\wamp\www\universal_empires\test_log.txt");
            error_log(" Reason given: $e->getMessage()",3,"C:\wamp\www\universal_empires\test_log.txt");
            return false;
        }
        
        try {
            if (count($res) === 0) {
                $sql="
                INSERT INTO
                    ue_user_session
                (
                      sess_id
                    , user
                    , start
                    , last_activity
                    , expires
                    , sess_data
                )
                VALUES
                    (
                          :sess_id
                        , '0'
                        , NOW()
                        , NOW()
                        , DATE_ADD(NOW(), INTERVAL 30 MINUTE)
                        , :sess_data                        
                    )                
                ";
                $stmt->bindParam(':sess_id', $session_id);
                $stmt->bindParam(':sess_data', $session_data);
            } else {
                $sql="
                    UPDATE
                        ue_user_session
                    SET
                          last_activity = NOW()
                        , expires = DATE_ADD(NOW(), INTERVAL 30 MINUTE)
                        , sess_data = :sess_data
                    WHERE
                        sess_id = :sess_id                
                ";
            }
            $stmt = $this->db->prepare($sql);
            $stmt->bindParam(':sess_id', $session_id);
            $stmt->bindParam(':sess_data', $session_data);
            $stmt->execute();
            return true;
        }
        catch (PDOException $e) {
            error_log('Error reading the session data table in the session reading method.',3,"C:\wamp\www\universal_empires\test_log.txt");
            error_log(" Query with error: $sql",3,"C:\wamp\www\universal_empires\test_log.txt");
            error_log(" Reason given: $e->getMessage()",3,"C:\wamp\www\universal_empires\test_log.txt");
            return false;
        }
    }
    
    public function destroy($session_id) {
        try {
            $sql="
                DELETE FROM
                    ue_user_session
                WHERE
                    sess_id = :sess_id
            ";
            $stmt = $this->db->prepare($sql);
            $stmt->bindParam(':sess_id', $session_id);
            $stmt->execute();
            return true;
        }
        catch (PDOException $e) {
            error_log('Error reading the session data table in the session reading method.',3,"C:\wamp\www\universal_empires\test_log.txt");
            error_log(" Query with error: $sql",3,"C:\wamp\www\universal_empires\test_log.txt");
            error_log(" Reason given: $e->getMessage()",3,"C:\wamp\www\universal_empires\test_log.txt");
            return false;
        }
    }

    public function gc($max_lifetime) {
        try {
            $sql="
                DELETE FROM
                    ue_user_session
                WHERE
                    last_activity < expires
            ";
            $stmt = $this->db->prepare($sql);
            $stmt->execute();
        }
        catch (PDOException $e) {
            error_log('Error reading the session data table in the session reading method.',3,"C:\wamp\www\universal_empires\test_log.txt");
            error_log(" Query with error: $sql",3,"C:\wamp\www\universal_empires\test_log.txt");
            error_log(" Reason given: $e->getMessage()",3,"C:\wamp\www\universal_empires\test_log.txt");
            return false;
        }
    }

    public function __destruct() {
        session_write_close();
    }
}
?>

htaccess

 RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    
    RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

Things ruled out:

  • Javascript: Only script present now is TinyMCE, any other javascript deleted
  • Browser: Same thing occurs with both FF and Chrome
  • WAMP 32bit verus WAMP 64bit (same thing occurs with both
  • Transactions: All lines relating to the starting of, commiting or rolling back transactions have been commented out

5.5.12 is the version of PHP in use

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.