Fork me on GitHub

Using class files in modules?  Bottom

  • This is probably a stupid question, but I'm teaching myself PHP so I'm not entirely educated on this:


    I noticed in the current stabe release of PN, one could call a PHP class file from a module function e.g.:

    Code

    function MyMod_user_func() {
        include( "modules/MyMod/MyClass.php" );

        $myC = new MyClass();
    }


    My module uses flash as well, so remoting is needed, but now in PN .8, everything is protected (no more die("you can't access this file directly") I'm guessing?) with 644 (not sure if that was the case before, but I never had a problem before). That's all good, but I can't use that class in a pnuser function and don't know how to give permission to the pnuser file (or my .fla file) to access the class file (it's in a specified folder in my module) and chmodding them to 755 doesn't work (isn't really safe either). This might be a newbie question, but could anyone explain how permissions in PN .8 work and how I could fix that problem? Thanks in advance.



    edited by: leshaun, Mar 05, 2007 - 06:03 AM
  • We don't need the direct access die anymore since everything is within a function or class - no code is executed on a direct access

    Your code above will still work ok. However if you want to do things in a more standard fashion you can use the loader class

    Code

    Loader::loadClassFromModule ('<your module>', 'class file stub');


    e.g. The following code will load the file PNmylass.class.php from the directory modules/mymod/classes/. After this create your new object as you would before.

    Code

    Loader::loadClassFromModule ('mymod', 'myclass');


    -Mark

    --
    Visit My homepage and Zikula themes.
  • Oh ok, I forgot about those new classes; thanks for that. But what if I need to call that class from Flash? I use AMFPHP to connect the flash app to some PN functions, but it gives me a loading error now. Would I have to change the permissions of that file, or is there something more to the security in PN .8?



    edited by: leshaun, Mar 05, 2007 - 12:22 PM
  • Sorry but i've no experience of flash or any problems arising from it.

    What does file permissions have to do with flash?

    -Mark

    --
    Visit My homepage and Zikula themes.
  • markwest

    What does file permissions have to do with flash?


    I was asking myself the same question lol. It have something to do with a file outside of the PN framework trying to access the folders. It's ok, I found somewhat of a fix for it.
  • I think I see what your getting at now.... There's a .htaccess file in the modules folder that prevents direct access to any of the PHP code. This is there for additional security. You could supply an additional .htaccess file in your module to override this if you wanted.

    One common factor in many security issues of web applications is the calling of files from that application directly rather than through the applications entry point. This is a way of preventing.

    -Mark

    --
    Visit My homepage and Zikula themes.
  • Oooooh, that didn't even cross my mind. Thanks Mark, a lot of your code is the reason I've been able to teach myself PHP and use efficient techniques. Thanks again.

    EDIT: I'm not entirely sure if there would be a way for flash not to call that class file, any suggestions would be good, but either way, that file itself doesn't seem to present any access to anything else.



    edited by: leshaun, Mar 05, 2007 - 07:28 PM

This list is based on users active over the last 60 minutes.