I'm trying to access the drupal sessions from an external php file (still on the same server -- just not a drupal page).

In there I've got (As has been suggested by IRC):

require_once("./includes/bootstrap.inc"); 
require_once("./includes/common.inc"); 
drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSIONS); 

And although they don't produce any errors when executing, the $_SESSION array remains empty on the external page when I try to access it.

Has anyone done this before or know an extisting script that does this so I can go code-thieving?

Comments

markus_petrux’s picture

Strange, that code snippet looks good.

By "same server" do you mean "same exact domain"? ...or is from different subdomains?

Doubt is the beginning, not the end of wisdom.

OliW’s picture

Yes, "same exact domain". Its just a file in the root dir of the same site. Drupal is installed in the root dir too.

Oli Warner
KittenAuth.com

markus_petrux’s picture

Try this:

require_once("./includes/bootstrap.inc");
drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION); // typo was here ;-)

echo '';
var_dump($_SESSION);
echo '';

Doubt is the beginning, not the end of wisdom.

OliW’s picture

If you were here and we were both "that way" i would be sexing you up so hard right now...

Fantastic catch! Working like a charm now! Damn its been a long 6 hours to get that done =)

Oli Warner
KittenAuth.com

Edit: is there anything I need to do to "close" the thread or do they just sink away and get archived?

markus_petrux’s picture

AFAIK, forum posts aren't closed like project issues.

Doubt is the beginning, not the end of wisdom.

chx’s picture

I suggested this to you and have not mentioned common.inc . That's not needed for sure.
--
The news is Now Public | Drupal development: making the world better, one patch at a time.

--
Drupal development: making the world better, one patch at a time. | A bedroom without a teddy is like a face without a smile.

OliW’s picture

Sorry that's something I picked up from the integration handbook thingy...
Doesn't affect the outcome of the test though =( Still fails without common being inc'd

I'll try it on another install (this time with 4.6 --maybe) with another script, just to make sure what I'm getting isn't the result of my incompetance.

Oli Warner
KittenAuth.com

amit123’s picture

can u provide me complete code snippets for this also i would like to access drupal database from external file how could i do that

drupalfantwo’s picture

what should i put?

for example:
httpdocs/sub1/sub2/bootstraptest.php

I tried doing this

require_once("../../includes/bootstrap.inc");

Then it gave me this error
Warning: conf_init(./sites/default/settings.php): failed to open stream: No such file or directory in /var/www/vhosts/domain.com/httpdocs/includes/bootstrap.inc on line 243

Warning: conf_init(): Failed opening './sites/default/settings.php' for inclusion (include_path='.:') in /var/www/vhosts/V/httpdocs/includes/bootstrap.inc on line 243

Warning: _drupal_cache_init(./includes/cache.inc): failed to open stream: No such file or directory in /var/www/vhosts/domain.com/httpdocs/includes/bootstrap.inc on line 893

Fatal error: _drupal_cache_init(): Failed opening required './includes/cache.inc' (include_path='.:') in /var/www/vhosts/domain.com/httpdocs/includes/bootstrap.inc on line 893

any insight would be appreciated :)

Thanks :D

geertv’s picture


    $currdir=getcwd();
    chdir($_SERVER['DOCUMENT_ROOT']);
    require_once("./includes/bootstrap.inc");
    drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION);
    chdir($currdir);

// rest of your code...