By jpulles on
The carto module has to make several calls to external php scripts that use $_SESSION to 'remember' some variables. The external php scripts by themselves work well, but when called from Drupal it seems that the session variable looses its value.
Is this 'problem' of Drupal familiar to anyone and is there a known solution?
Thanks,
John.
Comments
different php settings
The problem is that the call to the external php script gets different php settings, especially a different session.save_handler which is 'files' instead of the 'user' session.save_handler of drupal.
same problem
I'm having the same problem... The scripts work fine on windows and linux, but Drupal seems to break them. I can display variables on "page1" using:
echo $_SESSION['myVar'];, but when I follow a link to "page2", myVar is empty. Session ID stays the same."Page1" is displayed as a php page INSIDE of drupal, "page2" is a php page either in a new window, or a page OUTSIDE drupal (within the same domain).
When I link back to page1 from page 2, my session vars are back.
I've set session.save_handler to user and files with the same results.
I don't want to save the vars in the cookie or db, how else do we access drupal session vars from outside? It seems the drupal vars are still available from outside, but not the vars that I am setting.
Problem happens in IE and Firefox, so I assume this is not client side.
Thanks,
Mark.
Update
By moving all "external" script files to the Drupal root dir, rather than in it's own dir, and including includes/bootstrap.inc and includes/common.inc at the top of the script, all seems to be working. I can access all of my vars with $_SESSION[].
I tried to just include the files while leaving my scripts in their own dir, but I ran into path issues.
This seems to be working now, but I would prefer to have my scripts in their own dir to keep things neat.
Any suggestions?
Mark.
Seconds...
By putting files inside of Drupal's root, and including BOOTSTRAP and COMMON the file essentially becomes a Drupal page, is there a solution for sharing SESSION vars between Drupal and other apps running side by side in the site's root without moving anything around?
What exactly is making this break? (Please explain in simple terms ;-) ) My understanding was that SESSION vars are set at the DOMAIN level, and that different apps on the same server should easily be able to share them.
Question answered.
Thanks again yelvington.
Sessions - yelvington - October 11, 2005 - 07:42
http://drupal.org/node/32436#comment-59947
I know this is old...
...but the common.inc include is the holy grail of getting an external php script to keep it's session variables from a Drupal session, and therefore keeping a user "logged in".
I have a simple php script, called by an ajax script, but I wanted to guarantee that the user submitting data to the script, had permission to do so. I check each piece of data being changed, and if even a single data point is wrong, the submission does not go through. On a site with lots of users, all performing the same functions, this can turn disastrous if/when someone gets experimental, and starts messing with other users data.
In my case I kept it simple, but like I said I tried a variety of things, including DRUPAL_BOOTSTRAP_SESSION and that didn't work.
I'm having a similar
I'm having a similar problem... did you get it working?
Yes I did
You have to include the includes/common.inc as rnsi noted above.
My implementation of external php script with ajax, and drupal "booting", into the user, absolutely works, using this.
I am sure there is a better way to do this, but I really wanted to keep it simple, and this seemed to be the best method.
How to use Global Session Variables from Drupal in out scripts.
Firsts at all, I'm sorry for my little english.
I'd the same problem and I found the solution in the next url: http://drupal.org/node/258208
You must be include the next lines in your script for activate the session variables defined in Drupal. Drupal not use the tipycal configuration to manipulate de Global Session, Drupal define de Global Session in the Database. For this case, if you use the typical function (session_start(), $SESSION['variable'], etc) your script don't know the Drupal values because is not declared for this procedure.
The lines that you must be include are (Remember!!!, put your php script in the main Drupal folder where index.php lives):
With drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); load the Full specitification and values. If you only need the Session Values you can be change this line to drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION);
Thank you for the all people that contributed in Drupal Project.
Thanks for your post. I'm
Thanks for your post. I'm using this method right now, but the $user is logged in while within Drupal and logged out while within my external script. Do you know how to ensure that the 2 bootstraps are seeing me as the same user?In D7 the normal bootstrap starts with define('DRUPAL_ROOT', [path]); which you could just use like follows:
and all will be available.
Worked
Hi,
After struggling for weeks this did the trick. Thanks.
ie works fine but..
I want to get global $user variable from an outsite php file.
I tried your solution and it works fine with ie but not with chrome or firefox.
what could be reason, any idea?
thanks in advance
Are you not logged in with
Are you not logged in with the other browsers? The PHP logic is not going to change from 1 browser to another. I wrote a short blog post on this which might have info that's helpful to you: http://www.csdesignco.com/content/using-drupal-data-functions-and-sessio...