Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
创建仅限于Joomla组的PHP页面_Php_Joomla_Joomla3.1 - Fatal编程技术网

创建仅限于Joomla组的PHP页面

创建仅限于Joomla组的PHP页面,php,joomla,joomla3.1,Php,Joomla,Joomla3.1,我已经创建了一个php页面,但是内容可能只适用于特定的组Joomla 该文件位于一个文件夹中,该文件夹位于joomla站点的根目录中 如何获取我的php页面,检查用户数据:UserGroupID / root / root / administrator / root / components ... / root / folder / root / folder / file.php 和file.php $content_to_group_id = 7; if ($group_id_use

我已经创建了一个php页面,但是内容可能只适用于特定的组Joomla

该文件位于一个文件夹中,该文件夹位于joomla站点的根目录中

如何获取我的php页面,检查用户数据:UserGroupID

/ root
/ root / administrator
/ root / components
...
/ root / folder
/ root / folder / file.php
和file.php

$content_to_group_id = 7;

if ($group_id_user == $content_to_group_id) {
// show
} else {
// error
}

可能最简单的方法是利用Joomla框架获取用户id,查询数据库中的#(uuu用户)(uu用户组)映射表中的匹配记录。下面的代码尚未测试,需要将Joomla框架加载到脚本中

$user =& JFactory::getUser();
$userID = $user->get('id');

// allowed group_id
$groupID = 7;

$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('user_id');
$query->from('#__user_usergroup_map');
$where->where('user_id = ' . $userID . 'and group_id = ' . $groupID); 
$db->setQuery($query);
$db->Query();
$num_rows=$db->getNumRows();

if ($num_rows === 1) {
  // only one matching record 
}
else {
  // Sorry, you aren't allowed here.
}
试试这个

使用以下代码将joomla框架加载到您的页面

define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );//this is when we are in the root
define( 'DS', DIRECTORY_SEPARATOR );

require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();

$user = JFactory :: getUser();//if you want to get current users details then empty params other wise pass like JFactory::getUser($user_id);
echo "<pre/>";
print_r($user)//This resulted array have the user group of the user.
define('u-JEXEC',1);
定义('JPATH_BASE',目录名(_文件__))//这是我们在根的时候
定义('DS',目录\分隔符);
require_once(JPATH_BASE.DS.'includes'.DS.'defines.php');
require_once(JPATH_BASE.DS.'includes'.DS.'framework.php');
$mainframe=&JFactory::getApplication('site');
$mainframe->initialise();
$user=JFactory::getUser()//如果您想获取当前用户的详细信息,则将参数清空,然后通过其他方式传递,如JFactory::getUser($user_id);
回声“;
print\r($user)//此结果数组具有用户的用户组。

希望它对您有所帮助。

注意您正在使用Joomla!3+,因此我上面的一些代码由于不推荐使用的方法和/或PHP版本而导致错误。下面是一些有用的行,尤其是$groups变量,它返回授权用户组的数组。然后,您只需对照数组$groups检查您的用户id

$user = JFactory::getUser();
$db = JFactory:: getDbo();
$groups = $user->getAuthorisedGroups();
$input = JFactory::getApplication()->input;

希望能有所帮助。

您的问题也是正确的,我认为这是解决方案的第二部分!但只有一个问题可以标记为正确!