• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CI4 running in apache server virtualhost. Failed to decode session object.

#1
Requesting multiple connection to the server using session() will return an error.

session_start(): Failed to decode session object. Session has been destroyed

I am using a virtualhost in my wampp server to connect to the public folder of CI4. Every time I have concurrent request to the server I will get this error and will redirect to the login page because the session was destroyed. 

I also added the line below to my virtualhost to save the sessions on a specific project.
php_value session.save_path "${INSTALL_DIR}/www/CI4/writable/session"

I got this error on php logs:

Quote:PHP Fatal error:  Uncaught ErrorException: Unknown: Cannot call session save handler in a recursive manner in Unknown:0

Do you have any idea about this? or can you recommend other way to point the specific project to the public folder? I can't change my DocumentRoot because there are multiple projects on my server.
Reply

#2
Must be a configuration problem because I am running file sessions on XAMPP with vhosts
with no problems.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
(10-23-2019, 06:08 PM)InsiteFX Wrote: Must be a configuration problem because I am running file sessions on XAMPP with vhosts
with no problems.

May I know your configuration on vhosts?
Reply

#4
I can show you one but you would need to edit it for yourself.

Code:
#--------------------------------------------------------------
# HTTP:
#--------------------------------------------------------------
<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/ci4test/public_html"
    ServerName ci4test.local
    ServerAlias ci4test.local
    <Directory "C:/xampp/htdocs/ci4test/public_html">
        Order allow,deny
        Allow from all
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

#--------------------------------------------------------------
# HTTPS:
#--------------------------------------------------------------
<VirtualHost *:443>
    DocumentRoot "C:/xampp/htdocs/ci4test/public_html"
    ServerName ci4test.local
    ServerAlias ci4test.local
    SSLEngine on
    SSLCertificateFile "conf/ssl.crt/server.crt"
    SSLCertificateKeyFile "conf/ssl.key/server.key"
    <Directory "C:/xampp/htdocs/ci4test/public_html">
        Options All
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

That's how I do it for both http:// and https://

I program using the https://

For the sessions I load it in my BaseController and extend all controllers form that.

PHP Code:
<?php
namespace App\Controllers;

/**
 * Class BaseController
 *
 * BaseController provides a convenient place for loading components
 * and performing functions that are needed by all your controllers.
 * Extend this class in any new controllers:
 *     class Home extends BaseController
 *
 * For security be sure to declare any new methods as protected or private.
 *
 * @package CodeIgniter
 */

use CodeIgniter\Controller;
use 
CodeIgniter\HTTP\RequestInterface;
use 
CodeIgniter\HTTP\ResponseInterface;
use 
Config\Services;
use 
Psr\Log\LoggerInterface;

class 
BaseController extends Controller
{

    
/**
     * An array of helpers to be loaded automatically upon
     * class instantiation. These helpers will be available
     * to all other controllers that extend BaseController.
     *
     * @var array
     */
    
protected $helpers = [
        'auth',
        'utility',
    ];

    /**
     * @var string - Holds the session instance
     */
    protected $session;

    /**
     * Constructor.
     *
     * @param RequestInterface  $request
     * @param ResponseInterface $response
     * @param LoggerInterface   $logger
     */
    
public function initController(RequestInterface $requestResponseInterface $responseLoggerInterface $logger)
    {
        
// Do Not Edit This Line
        
parent::initController($request$response$logger);

        
//--------------------------------------------------------------------
        // Preload any models, libraries, etc, here.
        //--------------------------------------------------------------------
        // E.g.:
        // $this->session = \Config\Services::session();

        // Ensure that the session is started and running
        if (session_status() == PHP_SESSION_NONE)
        {
            $this->session Services::session();
        }
    }

}


/**
 * -----------------------------------------------------------------------
 * Filename: BaseController.php
 * Location: ./app/Controllers/BaseController.php
 * -----------------------------------------------------------------------
 */ 

Hope that helps, you can use the session helper method or use regular session globals.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#5
(10-24-2019, 12:47 PM)InsiteFX Wrote: I can show you one but you would need to edit it for yourself.

Code:
#--------------------------------------------------------------
# HTTP:
#--------------------------------------------------------------
<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/ci4test/public_html"
    ServerName ci4test.local
    ServerAlias ci4test.local
    <Directory "C:/xampp/htdocs/ci4test/public_html">
        Order allow,deny
        Allow from all
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

#--------------------------------------------------------------
# HTTPS:
#--------------------------------------------------------------
<VirtualHost *:443>
    DocumentRoot "C:/xampp/htdocs/ci4test/public_html"
    ServerName ci4test.local
    ServerAlias ci4test.local
    SSLEngine on
    SSLCertificateFile "conf/ssl.crt/server.crt"
    SSLCertificateKeyFile "conf/ssl.key/server.key"
    <Directory "C:/xampp/htdocs/ci4test/public_html">
        Options All
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

That's how I do it for both http:// and https://

I program using the https://

For the sessions I load it in my BaseController and extend all controllers form that.

PHP Code:
<?php
namespace App\Controllers;

/**
 * Class BaseController
 *
 * BaseController provides a convenient place for loading components
 * and performing functions that are needed by all your controllers.
 * Extend this class in any new controllers:
 *     class Home extends BaseController
 *
 * For security be sure to declare any new methods as protected or private.
 *
 * @package CodeIgniter
 */

use CodeIgniter\Controller;
use 
CodeIgniter\HTTP\RequestInterface;
use 
CodeIgniter\HTTP\ResponseInterface;
use 
Config\Services;
use 
Psr\Log\LoggerInterface;

class 
BaseController extends Controller
{

    
/**
     * An array of helpers to be loaded automatically upon
     * class instantiation. These helpers will be available
     * to all other controllers that extend BaseController.
     *
     * @var array
     */
    
protected $helpers = [
        'auth',
        'utility',
    ];

    /**
     * @var string - Holds the session instance
     */
    protected $session;

    /**
     * Constructor.
     *
     * @param RequestInterface  $request
     * @param ResponseInterface $response
     * @param LoggerInterface   $logger
     */
    
public function initController(RequestInterface $requestResponseInterface $responseLoggerInterface $logger)
    {
        
// Do Not Edit This Line
        
parent::initController($request$response$logger);

        
//--------------------------------------------------------------------
        // Preload any models, libraries, etc, here.
        //--------------------------------------------------------------------
        // E.g.:
        // $this->session = \Config\Services::session();

        // Ensure that the session is started and running
        if (session_status() == PHP_SESSION_NONE)
        {
            $this->session Services::session();
        }
    }

}


/**
 * -----------------------------------------------------------------------
 * Filename: BaseController.php
 * Location: ./app/Controllers/BaseController.php
 * -----------------------------------------------------------------------
 */ 

Hope that helps, you can use the session helper method or use regular session globals.

This will still gives me the same error if i do multiple requests using ajax.
Reply

#6
@gentlemanoi
Quote:This will still gives me the same error if i do multiple requests using ajax.

I use Ajax and think that a separate PHP instance is started and does not recognise the parent constants and they have to be declared again Sad
download and make your system directory strict
Reply

#7
(10-29-2019, 10:39 PM)John_Betong Wrote: @gentlemanoi
Quote:This will still gives me the same error if i do multiple requests using ajax.

I use Ajax and think that a separate PHP instance is started and does not recognise the parent constants and they have to be declared again Sad

Yes. That's why I always got this error.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.