Search

Hello,
how do I achieve this behaviour? I have Members installed...

Thanks!

You mean redirecting upon a successful login? If so, see here.

Thanks David,
quite similar: I have a homepage where I host my login form. In case of returning logged-in user, I'd like to redirect him to the /projects page...

You can do this with the Page Headers extension.

After installing the extension, create a page named 'Logged In' with the page type 'headers', and use this as the template:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="xml"
    omit-xml-declaration="yes"
    encoding="UTF-8"
    indent="yes" />

    <xsl:template match="/data/events/member-login-info/@logged-in='yes'">
      HTTP/1.1 302 Moved Temporarily
      Location: <xsl:value-of select="concat($root, '/projects')"/>
    </xsl:template>

    <xsl:template match="/data/events/member-login-info/@logged-in='no'">
      HTTP/1.1 302 Moved Temporarily
      Location: <xsl:value-of select="$root"/>
    </xsl:template>

  </xsl:stylesheet>

To get your login form to redirect, add the following to your login form:

<input name="redirect" type="hidden" value="{$root}/logged-in" />

After that, everything should be working as you expect. You can change the url that you wish to redirect to by editing the 'Logged In' page template.


You can do some pretty neat things with Members and Page Headers together, like redirecting based upon user role:

<xsl:template match="/data/events/member-login-info/@logged-in='yes'">
  HTTP/1.1 302 Moved Temporarily
  Location: <xsl:value-of select="concat($root, '/', /data/params/member-role)"/>
</xsl:template>

I use this technique on one of my sites to redirect users from a single login form to separate admin / member dashboards, depending on what type of member they are.

No need for additional extensions... You can simply create custom event called event.membersloginredirect.php as shown below. Don't forget to change the redirect URL in the code. Now you can attach this event to any page you want people to redirect from if they are already logged in.

<?php

    require_once(TOOLKIT . '/class.event.php');

    Class eventmembers_login_redirect extends Event{

        public static function about(){
            return array(
                'name' => 'Members: Login Redirect',
                'author' => array(
                    'name' => 'Stephen Baux',
                    'website' => 'http://www.domain7.com/',
                    'email' => 'stephen@domain7.com'),
                'version' => '1.0',
                'release-date' => '2011-05-08T02:10:40+00:00'
            );
        }

        public static function allowEditorToParse(){
            return false;
        }

        public static function documentation(){
            return '
            <h3>Conditional Redirect</h3>
            <p>Attach this event to the Member Login page. When a member is logged in,
            this event will redirect to the URL specified in the <code>__trigger</code> method.</p>
            ';
        }

        public function load(){

            $Members = Symphony::ExtensionManager()->create('members');

            $Members->getMemberDriver()->initialiseCookie();
$isLoggedIn = $Members->getMemberDriver()->isLoggedIn();

            if($isLoggedIn) $this->__trigger();

        }

        protected function __trigger(){
            redirect(URL . '/dashboard/');
        }

    }

Symphony's redirect function (as used by @qnn) is fine in this case, because it will send a 302 status.

But using a 301 status for conditional redirects (as proposed by @ctruett) will potentially create massive issues. 301 means: This is forever. Browsers and proxies are allowed to never ask again, just cache the redirect. This is not the desired behaviour for a conditional redirect!

qnn: Neat! I have not yet dived into custom events, so thanks for the example.

michael-e: Thanks for clearing that up. I'll modify my post.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details