Community

Session ID different between Drupal and ajax file (external)

Hello,

[English is not my native language]

I try to load a block by ajax in a node template but I have one problem.
When I call my ajax file, the session_id() is different between drupal and my file. So I can’t use uid because in the ajax file the current user is anonymous…
How to get the same session ID in drupal and ajax file (external) ?

sites/all/themes/myTheme/template/node.tpl.php

<?php
$path_myModule
= base_path().drupal_get_path("module", "myModule");
print
session_id();
?>

<div id="myBlock">
</div>
<script>
(function ($) {
$(document).ready(function() {
jQuery('#myBlock').load('<?php print $path_myModule; ?>/ajax/ajax-block.php'); });
}(jQuery));
</script>

sites/all/modules/myModule/ajax/ajax-block.php

<?php
//script AJAX
define('DRUPAL_ROOT', 'D:\wamp\www\TaskTableBoard'); //in prod use: getcwd()
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

//load a block
$block = module_invoke('myModule', 'block_view', 'myIdBlock');
print
render($block);

print
session_id(); //this one is different...
?>

My code work without error and it is inspired by this page: http://groups.drupal.org/node/24825
I would to include ajax-block.php in the drupal’s environment to get the same session_id() result.

Note: when I refresh my page (node), the session_id() of my ajax file changes every time…

Thanks for your help

Fab78