1

I have made a folder in joomla directory. In this folder I have some file.

I want to authenticate these files from direct access using URL by name?

How can it be achieved?

shantanoo
  • 3,617
  • 1
  • 24
  • 37
tom
  • 13
  • 2
  • You can use .htaccess for it: look at this: http://stackoverflow.com/questions/11728976/how-to-deny-access-to-a-file-in-htaccess – user3097489 Mar 05 '15 at 19:25

1 Answers1

2

I'm not sure if this is the best way, but you can create a PHP script (let's call it joomla-auth.php) containing this:

<?php

define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__));
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');

if (JFactory::getUser()->id == 0)
   die("Access denied: login required.");

?>

Then, at the top of PHP scripts that need Joomla authentication, do:

<?php
include 'joomla-auth.php';
?>

If you have a PHP script, and you need to get information about the authenticated user, use JFactory::getUser() . If you have an .html file, you can change the extension to .php and add the 3 lines above to the top.

Chances are, creating a component or module is the "right way" to do what you're trying to do. However, I can't advise you on that because this is a lesson I still need to learn myself. You should also look into Jumi, which lets you embed PHP, HTML, JavaScript, etc. files directly into articles using a syntax like this:

{jumi myfile.html}{/jumi}
Joey Adams
  • 41,996
  • 18
  • 86
  • 115