0

I have a few pages with custom forms that interact with a database on the backend. However; none of the plugins that were meant to embed your PHP code inside of a Joomla article worked well enough. (They could not perform update queries.) In the end, the only reasonable thing was to create a few plain .php pages. However; these forms can be used to list tenants and their personal information. I need a way of restricting access to these pages to only registered Joomla users.

Is this possible? Alternatively, a library would also work fine. They do not need to be logged into the Joomla site for any reason other than these forms; so they could authenticate any other way. I just figured Joomla would be the easiest. Could it be as simple as placing the .php files inside a certain directory?

Thank you,

Jesse

1 Answer 1

1

You could try something like this.

<?php

    define( '_JEXEC', 1 );

    // defining the base path.
    define(JPATH_BASE,  $_SERVER[ 'DOCUMENT_ROOT']);
    require_once (JPATH_BASE .'/includes/defines.php' );
    require_once( JPATH_BASE .'/includes/framework.php' );

    // Creating an app instance 
    $app =& JFactory::getApplication('site');
    $app->initialise();

    jimport( 'joomla.user.user' );
    jimport( 'joomla.user.helper' );
    $user = JFactory::getUser();    
    $createdby = $user->id;

    if ($createdby == 0){
        // get the heck out of dodge! 
        echo "Opps, looks like you are not logged in.";
    }
    else {
        // else we are logged in and we can show the form
        echo "hello world, my form would go here.";


    }
?>

That might get you going for now.

However, I think a better approach would be to use a Joomla component builder to create basically an empty component that you could then plug your forms into. That would ensure you are following a proper Joomla MVC structure and using the authentication features correctly. Take a look at Joomla Component Creator to see an example of that type of tool.

HTH

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.