Trongate Way Docs

Login URLs and Routing

Now that you have written your configuration file, the login module knows about your users. But there is one more step: we need a way for people to reach the login form.

Every login form has a URL. The URL tells Trongate which module to load and which user level the form is for. There are two ways to build this URL.

Way 1: Using a Number (Simple)

If your config/login.php does not have a secret_login_word, you can use the user level's ID number directly:

http://yoursite.com/login/login/1   (for administrators)
http://yoursite.com/login/login/2   (for members)

The first login is the module name. The second login is the method that shows the form. The number (1 or 2) tells the module which user level this form is for.

Way 2: Using a Secret Word (Nicer)

If you set a secret_login_word in your configuration (like tg-admin or member-login), you can use that word in the URL:

http://yoursite.com/login/login/tg-admin    (for administrators)
http://yoursite.com/login/login/member-login (for members)

The login module looks at that last part of the URL (tg-admin or member-login), finds it in your configuration, and knows which user level to use.

If a user level has a secret_login_word, you cannot use the number version of the URL. For example, if members have the secret word member-login, going to /login/login/2 will show a 404 page. This is a security feature - it keeps your login URLs unpredictable.

Making the URL Even Shorter (Custom Routing)

Typing login/login/member-login every time is not very friendly. Would it not be nicer to just go to /member-login? That is what custom routing does.

Create a file at config/custom_routing.php and add:

PHP
<?php
$routes = [
    'member-login' => 'login/login/member-login',
    'tg-admin'     => 'login/login/tg-admin'
];
define('CUSTOM_ROUTES', $routes);

Now your users can visit:

  • http://yoursite.com/member-login - the member login form
  • http://yoursite.com/tg-admin - the admin login form

That is much cleaner, is it not?

To learn more about custom routing in Trongate, please refer to the Custom Routing documentation.

The Golden Rule of Custom Routing

The word you use in secret_login_word (in your config file) and the word you use as the route key (in your custom routing file) must match exactly. If one says member-login and the other says members-login, it will not work.

Tip: If you are not sure which way to go, use secret words with custom routing. It makes your login URLs clean and easy to remember.

What's Next

The login form is ready and the URL is set up. But what happens after someone logs in? On the next page, we will build the simple controller that welcomes your members and protects your pages.

We're continually improving the Trongate documentation. If anything is incorrect, unclear, incomplete, or could be better, we'd genuinely appreciate your input.

Share your thoughts in the Documentation Feedback.

Leave Feedback About This Page