Detect if a user is on the registration page

Is there a way to detect if a user is on the register page? I have been using  "$context == 'main' " to detect if the user is on the home page and if he has left in order to determine which stylesheet to show, however "$context == 'main" also seems to target the account registration page as well. 

Is there something I can use to target only the home page or alternatively, something I can use to target the account registration page? I hope that made sense

  • The home page corresponds to 'pg/dashboard', so you can check the URL, I suppose.  Alternatively, you can override the handler for the dashboard to sneak in your code.  Something like this in a plugin xyz may work:

    function xyz_dashboard_page_handler($path) {
        // do your stuff

        // invoke original handler
        global $CONFIG;
        $chain = $CONFIG->xyz_dashboard_chain;
        return $chain($path);

    // save original dashboard page handler
    global $CONFIG;
    $CONFIG->xyz_dashboard_chain = $CONFIG->pagehandler['dashboard'];
    if (empty($CONFIG->xyz_dashboard_chain)) {
        // There was no dashboard page handler???  Something not quite right ... oops
        register_page_handler('dashboard', 'xyz_dashboard_page_handler');

  • Putting

    echo get_context();

    in the registration page returns


    so I think that's your answer.


  • Thanks Kevin, learnt something new today :).

    but when i put echo get_context(); on account/register.php, it returns


    Weird... am I doing something wrong?

  • That's a bit weird. I put that code at the top of that page (Elgg 1.7) and that's what I get.

    No idea why you are getting something different.

     I imagine it's a server configuration thing.

  • It depends how you are accessing the register page... If through '/pg/register' get_context will return 'main' while if through '/account/register.php' get_contenxt() will return 'main' because context is set while handling the page request and not when accessing a view directly...

    I am also interested in a solution if anybody has one :)

  • strpos($_SERVER["REQUEST_URI"],"/register.php")