discuss.answer
-
☆ A M B ☆
- 24,524 Posts
You have to set the session_name to be the same as the MODx session. Around line 19 of the core/config/config.inc.php file defines the session name; this is a unique value generated during installation.
So you can just include the core/config/config.inc.php file in your .php script, and use the $session_name.
include 'path-to-/core/config/config.inc.php';
session_name($session_name);
session_start();
You may also be able to use a snippet for the script, as the content of a resource with no template. In that case it would already have all the MODx functionality. It depends on how the script is being implemented.
-
MODX Staff
- 10,725 Posts
If you want your script to authenticate a MODX user and redirect them to a protected page, you will need to log the user in to the appropriate Contexts in MODX from the same domain as the site. Do not create the session yourself if you expect MODX to use it, because MODX has very specific requirements for populating the session data. If your goal is to start a session and use MODX within your script, then you should be able to manage your session as you desire to.
Thanks Susan,
your second suggestion with a new resource worked very well. =)
--
André
-
☆ A M B ☆
- 24,524 Posts
I use this for AJAX processing all the time. In fact, such a resource-with-snippet can have several functions for dealing with however many AJAX requests your site may make; you don't have to have a separate resource for each AJAX-based function.
Makes life much easier for a lazy programmer!
Susan or phacer, would either of you care to elaborate on that method? I have a modal window for an school alert that will fire on any page load since I'm not sure where the user will enter from but it will need to be seen (school related). However, I don't want it to appear again as the user browses the site. I'm looking for the most efficient way to check for a session.
Thanks...I'm going to give this a shot. It looks like what I need but I was getting confused on the whole deal.
@phacer - pardon my ignorance on this subject. I haven't worked in coding PHP in a while and I'm still learning MODx. I plugged in your suggested snippet and I it registers the session as expected. My question is how do I translate that in to my modal window firing or not? I am using the "If" plugin to do some conditional stuff on whether the alert modal is turned on by a user setting. If you could somehow tie you plugin into that eval I'd be all set. It is just beyond me on how to pass that type of info in MODx.