I am creating a new page that is getting redirected from the Administrator page in Joomla 2.5.The page is getting displayed when i type the URL in browser . I need to restrict the view such that it can be visible only when the administrator logs into his account . Can you help me on this ?
This is my code:
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' );
$app = JFactory::getApplication('site');
$user = JFactory::getUser();
if ($app->isAdmin()) echo 'Running from Joomla Administrator site <Br/>';
//$app->isAdmin() always through null value
print_r($user);
echo $user->username;
When i login from my site this code works perfectly but when i login using administrator interface this code display's null value. i don't know why. is there any mistake in it? I get this output when i login using Administrator interface:
JUser Object
(
[isRoot:protected] =>
[id] => 0
[name] =>
[username] =>
[email] =>
[password] =>
[password_clear] =>
[usertype] =>
[block] =>
[sendEmail] => 0
[registerDate] =>
[lastvisitDate] =>
[activation] =>
[params] =>
[groups] => Array
(
)
[guest] => 1
[lastResetTime] =>
[resetCount] =>
when i login as a site user from my site (member login) i get this:
JUser Object
(
[isRoot:protected] =>
[id] => 2
[name] => name of user
[username] => username
[email] => [email protected]
[password] => 695c263968014c89bbf3159aa4:YoBWR6uzmUBMcqfj5hPzCIp7a6maYd
[password_clear] =>
[usertype] =>
[block] => 0
[sendEmail] => 1
[registerDate] => 2014-11-24
[lastvisitDate] => 2014-11-25 15:29:45
[activation] =>
[params] => {}
[groups] => Array
(
[2] => 2
)
[guest] => 0
I suffering with this problem for last 8 days. can you help me with this..
Be sure you're loading Joomla to start with (See this question at Joomla Stackexchange),
Update Added complete script.
Save this code in a php file located in the root of your Joomla folder. It will work, and you'll see the output. From there, you can adapt it's location and such to work with whatever you're trying to accomplish.
VARIATION FOR USE IN
\administrator