Welcome Guest, Not a member yet? Register   Sign In
Undefined variable: _SESSION
#1

I'm developing a pretty large project with CI4 and things have been working out pretty well so far. This is the first time I've run into an issue and cannot figure out why. php spark won't load with the following code in place:

C:\Users\Kyle\Desktop\OGD\framework>php spark serve

CodeIgniter CLI Tool - Version 4.0.0-alpha.2 - Server-Time: 2018-11-20 09:45:28am


An uncaught Exception was encountered

Type:        ErrorException
Message:     Undefined variable: _SESSION
Filename:    C:\Users\Kyle\Desktop\OGD\framework\system\Session\Session.php
Line Number: 474

If I comment out the following code php spark serve will work:

PHP Code:
<?php
namespace App\Filters;

use 
CodeIgniter\HTTP\RequestInterface;
use 
CodeIgniter\HTTP\ResponseInterface;
use 
CodeIgniter\Filters\FilterInterface;

class 
AuthUser implements FilterInterface {

    public function 
before(RequestInterface $request) {
        
$session session();
        
$user $session->get('user');

        if (empty(
$user['id'])) {
            return 
redirect('login');
        }
    }
    
    public function 
after(RequestInterface $requestResponseInterface $response) {

    }
}
?>

I think the real offending line is:

PHP Code:
return redirect('login'); 

I can run php -S localhost:8080 and it all works. Is this because the code is running through the CLI?

Any thoughts?
Reply


Messages In This Thread
Undefined variable: _SESSION - by NiteRaven - 11-20-2018, 08:56 AM
RE: Undefined variable: _SESSION - by NiteRaven - 11-20-2018, 04:12 PM
RE: Undefined variable: _SESSION - by ciadmin - 11-20-2018, 05:50 PM
RE: Undefined variable: _SESSION - by NiteRaven - 11-20-2018, 06:18 PM
RE: Undefined variable: _SESSION - by natanfelles - 11-20-2018, 08:34 PM
RE: Undefined variable: _SESSION - by kilishan - 11-20-2018, 08:36 PM
RE: Undefined variable: _SESSION - by kilishan - 11-22-2018, 09:49 PM
RE: Undefined variable: _SESSION - by NiteRaven - 11-24-2018, 10:42 AM
RE: Undefined variable: _SESSION - by NiteRaven - 12-02-2018, 03:14 PM
RE: Undefined variable: _SESSION - by kilishan - 12-03-2018, 02:03 PM
RE: Undefined variable: _SESSION - by NiteRaven - 12-03-2018, 02:26 PM
RE: Undefined variable: _SESSION - by kilishan - 12-03-2018, 02:34 PM



Theme © iAndrew 2016 - Forum software by © MyBB