I want to get $user->uid (if authenticated user popped it up) from the
window, popped up by drupal site (not drupal window) *without*
transferring uid as parameter. Is it possible, and if it is, so how?

Thank you

Comments

Scott Reynolds’s picture

global $user;
if ($user->uid != 0) {
// Pop up
}

global $user is a constant that holds the current user information

WebRIPPER’s picture

No, from the popped up window
javascript:window.open('mywindow.php');
I want to get $user->uid in mywindow.php, not in oppener

utterly_lost’s picture

i'd look at the contents of the index.php in your root drupal directory, check whats gets included/executed, maybe pop some derivative include of it into your page, probably the bootstrap.inc and work from that....

in fact ive just done a little test on a totally unrelated page, foo.php that i put in the root directory and this:

<?
require_once 'includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
echo $user->uid;
?>  

will pull out the user id so you can then work from that ie:

if($user->uid != 0) {.......etc etc

hth

tim

Scott Reynolds’s picture

that works if you do this:

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

   global $user;

   echo $user->uid;
neubreed’s picture

One thing to note, if you want the url paths to be correct, as in base_path(), path_to_theme() etc. make sure you set $base_url as well.

Here's a variation that I used to get a "free-standing" popup php script to work that includes the whole drupal environment

ie

  
   $GLOBALS['base_url'] = 'http://'.$_SERVER['HTTP_HOST']; // or whatever your drupal root is

   // get the base drupal directory and change to chdir to it
   $base = str_repeat('../',substr_count($_SERVER['PHP_SELF'],'/')-1);
   chdir($base);

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

   global $user;

   echo $user->uid;

  echo '... and anything else you want!<br />';
barbara1712’s picture

Hello,
I am having the same problem. But instead of popup, I have used the iframe in my drupal.
so supoose in my iframe I open say 'mypage.php', so in 'mypage.php' I want user id
I have tried the code but I am getting warning.

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

   global $user;

   echo $user->uid;

The warning I am getting is
Warning: ini_set() [function.ini-set]: A session is active. You cannot change the session module's ini settings at this time. in yoursite.com/drupal/sites/default/settings.php on line 134

Warning: ini_set() [function.ini-set]: A session is active. You cannot change the session module's ini settings at this time. in yoursite.com/drupal/sites/default/settings.php on line 136

Please help me out.