Bootstrapping and user

I have a bootstrappped page that I am hoping to link to from a regular Drupal page.  I would like the bootstrapped page to know who the users are, but straight off $user object will only show you as anonymous user.  What I would like to know is if there is a designated way by Drupal to retrieve this information in any ways?  If not, I will stop investigating this way...  Any insights would be great.  Thanks.

ok

Did some tinkering around and investigation.  It seems user_load with global object $user seems the way forward.  The bootstrapped blank page will be linked from a fully fledged Drupal node page, so I will pass the user name or id to this blank page from the drupal page, and, at the top of the bootstrapped page, I did:

require_once("includes/bootstrap.inc");
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
<!-- All the boot strapping stuff done above here -->
// I will not dare extend the debate as to if we should passing user information this way...  :P
$id = $_POST["passed_id"];
global $user;
$user = user_load(array('uid',$id));

This will sort the cookie-session relationship "sorted" superficially (as in, creates a new session instance for good or bad and keep track of it) and creates a session for the user.  If you care the session table to capture the correct number of actual user/session instances per IP address, it may need to be some other method...

This comment thread of the post was reasonably convincing enough so that it has stopped me from investigation further:

http://drupal.org/node/49385#comment-93506

Thought I would post my solution just in case anyone may be interested.  (If you have a better solution, I would be interested...) Smile

darren's picture

no no no!

It's really not a good idea to be assigning to the global $user object.  

Why do you need to bootstrap this outside of Drupal? Can you not create the page using the standard method of implementing hook_menu() and putting your code in a page callback function?

 

Pop up page

Hi, Darren,

I am createing a pop up which will display a vertically framed page, top bit showing the file upload interface and bottom bit showing the uploaded file (such as PDF) if any.  The file inforamtion gets stored in postgres table and the table includes "last updated by" column, which needs the username.

I do not want to have the navigation if I can avoid.

I have a fully drupal incorporated page, which runs as a data storing application (the type which has a list view whose record links take you to the detail section of the record that users click on).  In a detail view, I would like to have a document icon, which will generate this pop up. 

Presumably hook_menu can be used when you are fully embracing the navigation, theme etc?  Though I am not fully aware of the power of the hook_menu perhaps...

Bootstrapping includes

Bootstrapping includes session initialisation for the page request so you shouldn't need to mess with global $user - it should be correctly instantiated automatically using Drupal's SESSxxxxx... cookie. But note that if your script is not located in the Drupal root folder (where Drupal's index.php lives) then you will need to set $base_url in settings.php to the correct URL for the Drupal site.

I see, so...

Hi, gpk,

*** With $base_url set explicitly as suggested in settings.php ***

Prep: cookie cleaned, no trailing sessions exists in session table, in settings.php I set $base_url to be explicit

After the first access to the drupal page as annon:

 uid |               sid                | timestamp  | cache
-----+----------------------------------+------------+-------
   0 | a31c89951f5333516755a13d62cae4e1 | 1266333488 |     0

Then after logged on:

uid |               sid                | timestamp  | cache
-----+----------------------------------+------------+-------
   2 | 26c7f351110def9a06e30658464974a6 | 1266333530 |     0

Then after loaded the separate boot strap page:

 uid |               sid                | timestamp  | cache
-----+----------------------------------+------------+-------
   0 | 26c7f351110def9a06e30658464974a6 | 1266333554 |     0

At this point when I loaded the bootstrap page, $user object var_dump will show user object for uid 2.  But it stores uid 0 in session table.

Your suggestion stays on the same session id, but uid gets reset to annon.

But then, if you do the following:

require_once("includes/bootstrap.inc");
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
global $user;
user_load(array('uid' => $user->uid));

It seems to work smoothly.  i.e. It looks like this:

 uid |               sid                | timestamp  | cache
-----+----------------------------------+------------+-------
   2 | 26c7f351110def9a06e30658464974a6 | 1266333554 |     0

Did your solution mean it this way?

Does this come across as a viable solution to you?