views:

64

answers:

2

I have integrated WHMCS and Drupal. However, when you go to Drupal and you print_r the SESSION, you see completely different information than what you would do if you go to the WHMCS pages. So, my question is, how do I access the one's session, from the other one?

I need to access it, in order to see if the user is logged in or not.

+1  A: 

The values you'll get depend on the session.name directive in php.ini. If you want them to be able to read each others', then set the same session.name.

Or rather, session data will be loaded based on the identifier in the cookie with the same name as session.name. This defaults to PHPSESSID, but you can change it yourself.

You can set this at runtime using ini_set() or session_name().

Daniel Egeberg
Sure, but all `session_name()` does is changing that directive. See: http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3/ext/session/session.c?view=markup#l1589
Daniel Egeberg
In the case of Drupal, the session name is set through code, not a `php.ini` directive.
kiamlaluno
Hmm... how did your comment manage to move below mine?
Daniel Egeberg
@Daniel Egeberg: The session name used by Drupal is different from the session name reported in `php.ini`; `php.ini` doesn't report the name of the session currently set. I take that the problem the OP is having is to read the session created from Drupal using WHMCS, or vice versa. I deleted my comment because I was not able to edit it, and it contained a typo; as it was the only comment, I thought I could do it. `:-)`
kiamlaluno
@kiamlaluno: It doesn't matter if it is set in `php.ini`. It's the name of `session.name` at the time where `session_start()` is executed that determines it. `session_name()` can also get the *current* session name. The bottom line is just that they need to be the same *somehow*.
Daniel Egeberg
I'm still stumped though. Even if I can set the session names, can you access other sessions?
RD
@RD: Well, say that `session.name=PHPSESSID` (the default). If that's the case, then when you call `start_session()`, PHP looks for a cookie called `PHPSESSID`. It uses the value of this cookie to lookup the session data in the storage. It's simply a matter of telling PHP how it's supposed to find the information.
Daniel Egeberg
+1  A: 

Drupal register its own session handling functions through session_set_save_handler() during bootstrap (drupal_bootstrap()). It also sets it own session mame in conf_init().

Because of the Drupal's handlers, restoring the WHMCS' session name before using standard PHP session will not work. PHP will use Drupal's hanlder to open, read, write, etc. session information. All you will get is the data for a wrong Drupal's session returned from sess_read() when called by PHP.

One way to read WHMCS' session is to figure out how it is stored and to access it without using PHP's sessions functions.

Another way may be to undo what Drupal has done (changing session name and registering handlers) to restore default behaviors of PHP's session functions, read the WHMCS' session and restore Drupal's session name and handlers.

mongolito404