Welcome Guest, Not a member yet? Register   Sign In
Accessing CI session data outside of CI
#1

I have a folder in my
Code:
Codeigniter4/public/oldproject

where i have created a test.php so that I can access it using
PHP Code:
myci4site.com/oldproject/test.php 

In test.php

PHP Code:
$path realpath(dirname(dirname(dirname(__FILE__))).'/writable/session');
//ini_set('session.save_path',$path);
session_save_path ($path);
session_id$_COOKIE['ci4session'] );
session_start();

print_r($_SESSION); 
but it prints an empty array.

There is session data in the session which I can print in my Home controller e.g. myci4site.com/home/test which just contains

PHP Code:
$sess session()->get();
echo 
'<pre>';print_r($sess); 

What else I need to do to be able to get session data in my test.php?

I need to access this data for maintaining old code for the time being.
Thanks.
Reply
#2

If you review CI’s session class you will see that it is much more complex in configuring the session. You cannot simply access the session data without duplicating much of what the session class is doing.
Reply
#3

Hmm - I don't want to duplicate code etc and was hoping for an easier/quick fix.
Reply
#4

Depending on what handler/driver you will be using, using CI4's session outside of CI may not be that hard to do, as long as your are using PSR-4 autoloading. Looks like you just new up a driver (injecting config), and inject it into the session class constructor. There's probably a little more to it, but you shouldn't have to reinvent the wheel.
Reply
#5

(09-29-2018, 05:49 AM)skunkbad Wrote: Depending on what handler/driver you will be using, using CI4's session outside of CI may not be that hard to do, as long as your are using PSR-4 autoloading. Looks like you just new up a driver (injecting config), and inject it into the session class constructor. There's probably a little more to it, but you shouldn't have to reinvent the wheel.

Yes!. Thank you, I'll give it a go.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB