Third Light Developer Exchange

Code and templating community forum for developers and software integrators

You are not logged in.

Announcement

If you wish to join the Developer Exchange, please contact your account manager - this is to avoid unnecessary spam in the forums. Many thanks for your understanding.

#1 2013-10-15 12:58:43

sam
Third Light Staff
Registered: 2013-06-06
Posts: 6

Using the API to provide a login/logout button

Enterprise Edition Only

When integrating an IMS with a website it is helpful to provide login status (and possibly a basket) in the website pages. I recently did just this for a client and thought it might be useful to see how it was done.

We had two virtual servers, one for the website and one for the IMS library. Something like this (in your case replace your-domain with the domain you are using):

  www.your-domain.com
  library.your-domain.com

and we needed to share session information between them so we could display a login status.

Anyone with an Enterprise Edition can do this. First edit the ims.ini.local file, e.g., in our case:-

/opt/thirdlight/ims/configuration/ims.ini.local

and, add the line (again, replacing "your-domain" with the domain you are using):

$g_COOKIE_DOMAIN = ".your-domain.com";

Next add some PHP code to get hold of the session ID and query it to find out whether the user is "USER" (i.e. logged in) or "EVENT" (i.e. not logged in but still able to see events):

<?php

	include_once('api_client.php');

	$imsUrl = "put-your-IMS-url-in-here";

	try {
		$imsSessionClient = new IMSApiClient(
			$imsUrl, 
			NULL, 
			array(
				"EXTRA_PARAMS" => array(
					'sessionId'=>$_COOKIE['IMSSESSID']
			))
		);
	} catch (Exception $e) {}

	function getSessionUserType(){
		global $imsSessionClient;
		if ($imsSessionClient) {
			try {
				$user = $imsSessionClient->GetUserDetails();
			} catch (Exception $e) {
				return "EVENT";
			}
		return ($user['type'] == 1) ? "USER" : "EVENT";
	}


?>

(note: this uses the PHP API client which you can download and read about here)

Now you can getSessionUserType() and use it to display a login or logout button:

<?php 

	$sessionUserType = getSessionUserType();

	if ($sessionUserType == "USER") { 
		echo "<a href='$imsUrl/logout.tlx'>logout</a>";
	} else { 
		echo "<a href='$imsUrl/login.tlx'>login</a>";
	} 

?>

Offline

Board footer