Lasso Soft Inc. > Home

[session_vars]

Linksession_vars
AuthorJason Huck
CategorySession
Version8.x
LicensePublic Domain
Posted10 Feb 2006
Updated11 Feb 2006
More by this author...

Description

This tag, based on code posted by Adam Randall here, returns a pair array containing the variables within the given session. The tag must be loaded via LassoStartup, and will only return results when the value of [session_result] is "load."  Otherwise returns "Undefined." Currently works with "Local Default" (SQLite) or "External" (MySQL) sessions. "In-Memory" sessions are not supported.

Sample Usage

// display all the vars in the session with their values

if(session_vars('mySession') != 'Undefined');
	iterate(session_vars('mySession'), local('i'));
		#i->first + ': ' + #i->second + '
'; /iterate; /if;

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

define_tag(
	'vars',
	-namespace='session_',
	-required='name',
	-priority='replace',
	-privileged,
	-description='Returns an array of all the variables in the given session.'
);
	local(
		'in' = null,
		'out' = array,
		'key' = ('_SessionTracker_' + #name + '_' + session_id( -name=#name))
	);
	
	local('sql' = '
		SELECT data 
		FROM global_prefs 
		WHERE store_key = \'lasso_session_database\'
	');
	
	inline(
		-database='lasso_internal',
		-sql=#sql
	);
		local('dbname') = field('data');
	/inline;


	local('sql' = '
		SELECT data 
		FROM global_prefs 
		WHERE store_key = \'lasso_session_table\'
	');
	
	inline(
		-database='lasso_internal',
		-sql=#sql
	);
		local('tblname') = field('data');
	/inline;
	
	local('sql' = '
		SELECT * 
		FROM ' + #tblname + ' 
		WHERE session_key = \'' + #key + '\'
	');
	
	inline(
		-database=#dbname,
		-sql=#sql
	);			
		if(found_count);
			protect;
				local('data') = field('data');
				#data = decompress(#data);
				#in->unserialize(#data);

				if(#in->isa('map'));
					iterate(#in->keys, local('i'));
						#out->insert(#i = #in->find(#i));
					/iterate;
				else;
					return('Undefined');
				/if;
				
				handle_error;
					return('Undefined');
				/handle_error;
			/protect;
		/if;
	/inline;
	
	return(#out);
/define_tag;

Related Tags

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft