So you’re using the Remote Login plugin for elgg to display an elgg login form on another site of yours. Once this plugin is setup and enabled, it will detect remote login and will automatically bring the user back to the page where that user did login.
It is sometimes required to know who is the coming back user to provide more integration capabilities or personalize the user experience.
In order to get the user name at the external page, you can hack the logout event implemented in the Remote Login plugin to include the elgg user name as a parameter in the URL.
To do that, can simply edit the “logout.php” file located in the Remote Login plugin directory (“/mod/remotelogin/actions/logout.php”).
Change the following (near the top pf the file):
if (isset($_SESSION['remote_login_referer']) && $_SESSION['remote_login_referer'] != '') $redirect_after_logout = $_SESSION['remote_login_referer'];
and replace it with the following:
if (isset($_SESSION['remote_login_referer']) && $_SESSION['remote_login_referer'] != '')
{
$redirect_after_logout = $_SESSION['remote_login_referer'];
//Rename previous usernames... In case one is re-logging-in from the same page!
$redirect_after_logout = preg_replace ('/rlelggusername/', 'rlprevelggusername', $redirect_after_logout);
//Parameter name and value... The value should be saved here as the logout will clear the session
$paramName = "rlelggusername";
$paramValue = $_SESSION['username'];
//Check what to use for the parameter '&' or '?'
$separator = (strpos ($redirect_after_logout, "?")!==false) ? '&' : '?';
//Is there a # in the URL... if so... insert right before it... otherwise insert parameter at the end
$position = (strpos ($redirect_after_logout, "#")!==false) ? strpos($redirect_after_logout,"#") : strlen ($redirect_after_logout);
//Insert Parameter
$redirect_after_logout = substr_replace ($redirect_after_logout, "$separator$paramName=$paramValue", $position, 0);
}
This new code will add a parameter called “rlelggusername” to the URL. This parameter will hold the user name of the elgg user who did logout.

Comments