Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Im execution drupal from an external php file having following code
chdir($_SERVER["DOCUMENT_ROOT"]);
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
global $user;
But when I print $user object , Its always an anonymous user even if user is logged in to the site.
But This strange behavior is happening on one of the servers. Im using the same php code with same drupal version 6.22 on development server, Everything works fine there.
Thanks in advace
Comments
Comment #1
Elementica CreditAttribution: Elementica commentedI'm interested in this topic: I have a complex site configuration with a custom framework (name it "CF") side-by-side a D6 installation...
From D6 I need to access CF and I wrote a module for this (everything's fine).
From CF I need to access D6 and this is a problem: I think it's a matter of sessions, but I'm not sure what to check.
(I have a control in the code to prevent a "loop" while booting frameworks, as 1st calls 2nd, 2nd calls 1st and so on...)
I call
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
after setting $base_url and $cookie_domain and I use chdir to jump to D's folder.In my CF I don't use global variables.
It seems a problem with session's id (php's
session_id()
function), because querying D's DB I see logged users and nobody has current session's id.Comment #2
Elementica CreditAttribution: Elementica commented.
Under webroot I have:
/d6 (installation of D6)
/cf (installation of another custom framework)
I need to access from D6 to CF and back. I've written a custom module to get into CF from D6.
My main problem is to get into D6 from CF programmatically, mainly to perform a login.
I have a custom file in drupal's root folder, included in CF, with something like
(I found conflicts using sessions, so in CF I use sessions no more)
.
If I log into D6 (/d6/user)
user_is_logged_in()
returns false in CF.If I log (calling the function with an existing username-password) using
and then navigate to D6 I'm not logged in, while
user_is_logged_in()
returns the correct uid in CF. i.e. I could log in the same browser, using the same account, in D6 with two separate sessions: within CF (programmatically) and within D6's interface (using log-in form): I think, so, it's a matter of session's id.MY AIM IS to access D6 functions inside the other framework and I'd like that login/logout can be performed either programmatically or via D's interface.
.
Comment #3
Elementica CreditAttribution: Elementica commentedPresently I'm trying:
It works, but if I have pages
.../cf
and.../cf/subpage
sessions appear different, so if I log in the first one, I'm anonymous in the other and vice-versa. I think this is the same problem so that logging directly inside D6 doesn't work in CF and vice-versa.I'm not sure what to check...
Comment #4
Elementica CreditAttribution: Elementica commentedFor future reference.
Partially solved.
Setting cookie domain of D (variable
$cookie_domain
) insettings.php
to ".example.com" (being not example, actually, but the real domain used) I can log into D6 and retrieve user logged in CF.Meanwhile I'm trying to log from CF directly as
user_authenticate(...)
doesn't work (switching to D6 there's no user logged).$user = user_authenticate(...)
does the job in returning logged user back to the variable, but it seems that session is somehow "invalid", as switching to any other page of CF or even to D6 no user is logged in.Comment #5
Elementica CreditAttribution: Elementica commentedFor future reference.
Solved.
Digging into sessions, I've found problems with session_id, so investigating further I've seen session's id got erased somewhere... looking around I've found an unwanted
session_destroy
and erased it.Comment #6
b33tl3 CreditAttribution: b33tl3 commentedhello Elementica,
where did you find your unwanted "session_destroy" ?
I'm facing a similar problem.
- I got a php script that :
- log a user programmaticaly (via user_authenticate)
- and do a redirection toward a ubercart cart page (drupal_goto)
when I am on the cart page, each time I "update", "remove" items in the cart or checkout the cart, I got an error with the message "Validation error, please try again. If this error persists, please contact the site administrator".
It happens ONLY with safari. works OK with chrome and firefox !!!
thanks :)