Hi all!

Following question:

how do i commit/forward my drupal "session_id" which is initialised/showed in the node to a separate php-script?
(Without using http-GET etc.)

The /node/1 generates an session_id
and i want use this session_id in my separate php-script "/page2.php".

In the 5.Xth-version of Drupal it worked without any problems - the drupal-generated session_id
showed up in the /page2.php.

But now as i installed my programs on the testbed on drupal 6 - the programs, that relied on the session_id stopped
to work correctly.

Please, look at this example:

http://test.ei.by/

Thank you in advance!

Ilya

Comments

vovaodei’s picture

Admins, please keep this one

gpk’s picture

TBH I don't quite see how your page2.php managed to obtain the session id from the Drupal site. While the browser would have sent the cookie containing the session ID, there's no code in your PHP script to tell PHP that the cookie contains the ID. Maybe it was a lucky coincidence of defaults or something. What version of Drupal 5 were you using?

The basic approach to this question is to include the file ./includes/bootstrap.inc and then perform a partial or full Drupal bootstrap, depending on how much Drupal functionality you want. How much *do* you want?

More details to follow..

gpk
----
www.alexoria.co.uk

vovaodei’s picture

Hmm....

well.. in this script i do not need any of the drupal functions. I need only the session_id..

gpk’s picture

OK if your script is in the main Drupal directory (which it looks as though it is) then try:

require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);

I think that should be enough to ensure that the cookie domain/name used in the context of your script match Drupal's.

gpk
----
www.alexoria.co.uk

vovaodei’s picture

Yep,

it worked..

Even a

<?php
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION);
?>

've done it.

I'm just wondering, why it worked before in the 5th version,...

gpk’s picture

Possibly it worked in D5 because the PHP default session name parameter happened to match the cookie name used by Drupal for storing the session id. Since (?) 5.2 the cookie name includes an md5 hash so there's no chance of the PHP default matching this! See the last line of code here http://api.drupal.org/api/function/conf_init.

BTW DRUPAL_BOOTSTRAP_SESSION carries out more of the bootstrap than DRUPAL_BOOTSTRAP_CONFIGURATION, so if the latter works then the former certainly will ;)

gpk
----
www.alexoria.co.uk