您好我正在尝试根据会话ID从joomla会话表中获取数据。我正在使用代码,并且能够获得会话ID,但是当我试图根据提到的查询获取用户名时,我没有得到任何输出。如果查询中有问题,请帮助/指导我。我还检查了数据表的列名(如果我是错误的),那些是正确的。
session_start();
$_session_id=session_id();
echo "your session id is ".$_session_id;
$db = JFactory::getDBO();
$query = $db->getQuery(true);
// $query = "SELECT username". " FROM izj5n_session"." WHERE session_id = $_session_id";
/* $query->select('username');
$query->from('izj5n_session');
$query->where('session_id=$_session_id');*/
$query
->select('username')
->from('izj5n_session')
->where('session_id=$_session_id');
$db->setQuery($query);
$rows = $db->loadResult();
$itemrow = $rows;
print $itemrow;
答案 0 :(得分:1)
定义('_JEXEC')或死('限制访问');
jimport( 'joomla.filesystem.file');
JHtml :: addIncludePath(JPATH_COMPONENT。'/ helpers');
$ db =& JFactory :: getDBO();
$ user =& JFactory ::的getUser();
echo $ user-> username
答案 1 :(得分:1)
猜猜......
$query = "
SELECT username
FROM Izj5n_session
WHERE session_id = $_session_id;
";