Using concrete5 session variables in an external script

433 Views Asked by At

I'm using Concrete5 from an external script. (The endgoal is external authentication in another system). So I implemented it as mentioned here: Bootstrapping C5 from an external script

It works fine, I can access all of the classes. However, when using the Session class, the variables aren't stored for longer than one execution. So when running the following script, the output 'succes!' is never shown.

define('C5_ENVIRONMENT_ONLY', true);
define('REDIRECT_TO_BASE_URL', false);
require('index.php');

if(!Session::get('uID')) {
    echo ("Better luck next time...");
    Session::set('uID', 1);
    echo ("Var set: ".Session::get('uID'));
} else {
    echo("succes!");
}

Does anybody know what has to change to make this work?

1

There are 1 best solutions below

0
On

When run from the browser the session hash is stored in a cookie. Your script can create a session, but next time it runs it has no way of identifying it. Try writing the hash to a file and then look for and read that file to get the existing session.