Reply to post by ybong
Thank you for the time spent replying to my post.
I created the plugin. I have confirmed that the plugin is active and working.
In the plugin I tried to set a session variable. I'm not sure what you intended I should set there? Something must be set there so I can retrieve it in the filehandler.php
in the onLoginUser function in the plugin I added the following
Code:
$session->set('jlogged_in',1);
Why? because I need information in my external file that the user is logged in.
Code:
<?php
// filehandler.php place the file in the joomla root directory
// http://yourhost+joomla_base_dir/filehandler.php test by accessing the url.
define( '_JEXEC', 1 );
define( '_VALID_MOS', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__) .'/' ) );
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
// I must initialise and call getApplication or else I get no result, but getApplication requires an argument.
// if I only knew if the user was a frontend user or backend user the I could initalise the correct application.
$app1 =& JFactory::getApplication('administrator');
$app1->initialise();
$admin_session = &JFactory::getSession();
// same problem as in my first post. 'site' isn't loaded it's still 'administrator'...
$app2 =& JFactory::getApplication('site');
$app2->initialise();
$site_session = &JFactory::getSession();
if ($admin_session->get('jlogged_in') == 1) {
echo "Access granted";// for testing purposes
} else if ($site_session->get('jlogged_in') == 1) {
echo "Access granted";// for testing purposes
} else {
echo "Access denied"; ;// for testing purposes
}
?>
The session doesn't seem to be stored in the same 'place' if the user logged into the frontend or the backend. So I can't make it work with session.
You said It worked on your site? What did you add in the plugin? What did you add in the "filehandler.php" file (or what your external file is called)? Please explain in greater detail exactly what you did. I probably missunderstand you.
Currently this proposed solution is a step back, because I get the same result as with my solution in my first post but now I have added more code (a plugin) too.
a) I'm not sure I explained my issue enough.
b) I didn't understand what you proposed I should do.
c) You didn't understand my problem.
To reiterate the reason to my post:
I configured apache with mod_rewrite in my .htaccess file. This part works. If a request comes in to:
http://myjoomlasite/images/files/private/top_secret.pdf the request will be rewritten and transparently sent to the filehandler.php like this: filehandler.php?file?=/images/files/private/top_secret.pdf
the filehandler.php writes the top_secret.pdf as a response if the request comes from a logged in user.
Any user as long they are logged in. And
regardless if they logged in from the front end or the back end.
mod_rewrite works
output of the file as a response works.
The only part that doesn't work is the OR part in the if statement in my first post.
An other way around the problem would be if I in my filehandler.php could peek somewhere and find out if the user logged in via the frontend or the backend. But how and where do I peek to find out which application the user is using?
added:I found this regarding
http://docs.joomla.org/JFactory/getApplication the example on that page but I can't get that to work. When I try to run it I get
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 71 bytes) in /path_to_joomla/libraries/joomla/error/exception.php on line 117
I must add a argument to getApplication to avoid an error...