[lp_session_vars]

Description

Link: [lp_session_vars]
Author: Bil Corry
Category: Session
Version: 8.x
License: Public Domain
Posted: Feb. 12, 2006
Updated: Dec. 03, 2007
More by this author...

Returns all session vars, or if a session name is specified, just the vars for that session name.

Requires [lp_session_id]

Parameters

-session_name string, optional The session to return all vars for, optional. Default to return all session vars for all sessions.
-string boolean, optional Optionally returns the vars as a comma-delimited string.

Sample Usage

[

session_start: -name='test_session1', -uselink;
session_start: -name='test_session2', -uselink;
session_addvar: -name='test_session1', 'test1';
session_addvar: -name='test_session2', 'test2';
session_addvar: -name='test_session1', 'test3';
session_addvar: -name='test_session2', 'test4';
var:'test1'=123;
var:'test2'=456;
var:'test3'='abc';
var:'test4'='def';
var:'test5'='not stored in session';
var:'test6'='not stored in session';

]
<pre>
<b>Sessions Example</b>
<hr>
<b>Session IDs as reported by Lasso</b>
Session ID #1 = [session_id: -name='test_session1']
Session ID #2 = [session_id: -name='test_session2']
<hr>
<b>Session IDs as reported by lp_session_id</b>
['[lp_session_id] = '][lp_session_id]
['[lp_session_id: -vars] = '][lp_session_id: -vars]
['[lp_session_id: -form] = '][output: (lp_session_id: -form)]
['[lp_session_id: -form, -xhtml] = '][output: (lp_session_id: -form, -xhtml)]
['[lp_session_id: -url] = '][lp_session_id: -url]
<hr>
<b>Session IDs added by Lasso (view source)</b>

forms:
<form action=""><input type="text" name="test1" value="form1"></form>
<form action=""><input type="text" name="test2" value="form2"></form>

links:
<a href="">link1</a>
<a href="">link2</a>
<hr>
<b>Redirect Test</b>
[
	if: (action_param:'r') == '1';
		redirect_url:'sessiontest.lasso';
	else: (action_param:'r') == '2';
		lp_session_redirect:'sessiontest.lasso';
	/if;
	
	'<a href="?r=1">Normal redirect</a>\r\n';
	'<a href="?r=2">Session redirect</a>\r\n';
]
<hr>
<b>Session Vars</b>

All Sessions  = [lp_session_vars]
Session ID #1 = [lp_session_vars: 'test_session1']
Session ID #2 = [lp_session_vars: 'test_session2']
<hr>

</pre>
						

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
[

define_tag:'lp_session_vars',
	-description='Returns all session vars, or if a session name is specified, just the vars for that session name.',
	-priority='replace',
	-optional='session_name',
	-optional='string';
	
	local:'vars' = array;
	local:'session' = array;
	local:'varnames' = array;
	
	if: local_defined:'session_name';
		#session->(insert: '_SessionTracker_' #session_name '_Vars');
	else;
		// get session name and session ID as an array of pairs
		#session = (lp_session_id: -vars);
		// get just the name of the session
		#session->(foreach: {params->first = params->first->name; Return: True;} );
		// now get the variable name that stores the session variable names
		#session->(foreach: {params->first->(append:'_Vars'); Return: True;} );
	/if;
	
	iterate: #session, local:'i';
		if: (var: #i)->type == 'array';
			#varnames->(merge: (var: #i));
		/if;
	/iterate;
	


	if: local_defined:'string';
		iterate: #varnames, local:'i';
			#vars->(insert: #i + '=' + (var: #i));
		/iterate;
	
		return: #vars->(join:', ');

	else;

		iterate: #varnames, local:'i';
			#vars->(insert: #i = (var: #i));
		/iterate;
	
		return: #vars;

	/if;

/define_tag;

]

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular