S
S
Stepan2014-10-29 11:25:51
PHP
Stepan, 2014-10-29 11:25:51

How to work with sessions in MODx?

I wrote a snippet that writes data to the session, but the problem is that the snippet only works for authorized users. If an unauthorized user visits the pages, no session entries are made. How can this be fixed?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Azim Kurt, 2014-10-29
@Symphony

Write to cookies

E
Evgeniy Samoilenko, 2014-10-29
@samoilenkoevgeniy

It depends on how you generally record. Show at least the snippet code, chtoli

6
65536, 2014-11-04
@65536

Weird. Everything works. If you want access to the session from a custom script, then you need to add something like this at the beginning of it:

require_once '../../config.core.php'; // путь от вашего скрипта до файла конфига
require_once MODX_CORE_PATH . 'config/' . MODX_CONFIG_KEY . '.inc.php';
require_once MODX_CORE_PATH . 'model/modx/modx.class.php';

$modx = new modX();
$modx->initialize('web');

session_start() does not need to be called, it is called during initialization. In snippets, too, you do not need to call.
That's what was really needed (in custom scripts), so it was to add
some kind of random at the end without it, then save, then not save, then some obsolete data appears after 10 minutes. Try adding a dog in front at the end of your snippet.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question