in the external file i use:
$path = $_SERVER['DOCUMENT_ROOT'];
chdir($path."/drupal");
define('DRUPAL_ROOT', getcwd());
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
global $user;
print $user->name;//it returns nothing
This external file i load using AJAX. May be because of it i have these troubles?
xmlhttp.open("GET","localhost/drupal/sites/all/themes/MyBartik/templates**team.php***?team_id="+str,true);
But this code works:
$account = user_load(2);
print $accou开发者_JS百科nt->name;
How can I get the name of the current user in Drupal 7?
when i write:
print_r $user;
It returns:
stdClass Object ( [uid] => 0 [hostname] => ::1 [roles] => Array ( [1] => anonymous user ) [cache] => 0 )
instead of:
stdClass Object ( [uid] => 1 [name] => admin [pass] => $S$CyyoOFpUD2X.4w8PHsIpWVHinwFZGIG3ZS/uQCz8W/lollB7UwCT [mail] => foo@example.com...
Here it is the AJAX function:
function showTeam(str){
jQuery("#popup_content").fadeIn("slow");
if (str=="")
{
document.getElementById("jShowTeam").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("jShowTeam").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","http://localhost/drupal/sites/all/themes/MyBartik/templates/team.php?team_id="+str,true); xmlhttp.send();
}
Just had this same problem (with the exact same code). I'm sure OP moved on in the last 2 years, but I'll leave this here for you - yes you, reader.
Open this file:
sites/default/settings.php
And on about line 328 there is a commmented line like
#$cookie_domain = '.example.com';
Uncomment it and put your domain in there, don't forget to leave in the prefix dot. You'll have to log in again and it should work.
精彩评论