We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 48282
    • 6 Posts
    I will admit I am very new to PHP and have only elementary understand of the language, so when it comes to figuring out how to integrate a PHP app into our ModX site, I am unfamiliar with what is normal php and what is ModX specific. I of course want to learn to do this myself, but the deadline for this project is coming up at the end of the year, so any specific help you guys could offer would be great. As I mentioned, because my understanding of php is limited, many of the forum results and ModX manual online is not of a lot of help since I am having a hard time deducing what applies to my code.

    The Project: simply put this is a User Authentication app. We have a member's only section of our website and need to register users, then when they login - authenticate the login against the database. The Member's only content is free, so security isn't a big deal here, but I was able to find a great collection of code here: https://github.com/elpeyotl/Secure-login-and-registration-form - I updated the necessary files to point to the SQL database I plan to use, and the scripts worked great outside of ModX; however I don't know where to begin in terms of getting all of code into ModX.

    Components of the app:

    • PHP code on secured pages - (checks to see if they are logged in - usually goes above Doctype)
    • User Registration page - (takes username, email, password, hashes password to SHA-512, and sends to SQL database)
    • User Login Page - (takes the email/username and passwords, and checks with database record, redirects to secured home page if successful)
    • Login processing and Hashing scripts - (PHP script for login processing, Javascript for SHA512 hasing)
    • Functions PHP script - (holds all of the functions used through the scripts.)
    Obviously there is a bit more to it, but this is kind the gist broken out. I assume that the Login and Registration bits are resources, the secure code that checks if you are logged in would go on in a template for the secure pages, but that is all I know for sure.

    I did come across this page: http://stackoverflow.com/questions/18449880/custom-php-in-modx-with-a-snippet that mentioned adding the "if function_exists" before each function, but that did not seem to help.

    I can post any bits of my own code or the original code if it would help, but I did not want to clutter this up if you guys preferred to just download the github project and see for yourself.

    Thank you in advance for any advice you can give. I know I am asking a lot, but I hope you guys are able to point me in the right direction.
      • 3749
      • 24,544 Posts
      You might be better off just migrating the users into the site as MODX users and using MODX's built-in authentication, registration, Login, and protection for the member pages. Most of that is already in MODX or quickly added with a handful of easily installed extras. You might take a look at the Subscribe extra, which in combination with the Login extra, provides a wrapper for user registration.

      Rolling your own authentication based on an external database can be done, but it requires a plugin connected to the OnWebLogin System Event to authenticate the users in MODX. Once that's done, you can protect your pages with the standard MODX security permissions.

      Integrating existing code with MODX can be done, but many non-modx apps mix PHP and HTML code, which you can't do in MODX. In MODX, all PHP code has to be in a snippet or plugin, so conversion can be very time-consuming. Often, you can export the users from the other database to a CSV file and then import them into MODX with a simple utility snippet or one of the existing user import utilities.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting