[lp_session_id]

Description

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

Retrieves all current Session IDs and returns them as HTML <input>s, URL strings or an array of pairs.  Also can return the vars that hold the session ID(s).

Note that the XHTML option is automatically selected when the content-type is set to XHTML.

Parameters

-array boolean, optional Default. Tag will return session(s) as array: (pair: (test_session1)=(7F000001052d62603CuULL36B0FB)), (pair: (test_session2)=(7F000001052d62603CXQiw36B103))
-url boolean, optional Tag will return sessions(s) as array: (-session=test_session1:7F000001052d62603CuULL36B0FB), (-session=test_session2:7F000001052d62603CXQiw36B103)
-form boolean, optional Tag will return session(s) as array: (<input type="hidden" name="-session" value="test_session1:7F000001052d62603CuULL36B0FB">), (<input type="hidden" name="-session" value="test_session2:7F000001052d62603CXQiw36B103">)
-xhtml boolean, optional When used with -form, tag will return session(s) as array: (<input type="hidden" name="-session" value="test_session1:7F000001052d62603CuULL36B0FB" />), (<input type="hidden" name="-session" value="test_session2:7F000001052d62603CXQiw36B103" />)
-vars boolean, optional Tag will return the *vars* that hold the session IDs as array: (pair: (_SessionTracker_test_session1)=(7F000001052d62603CuULL36B0FB)), (pair: (_SessionTracker_test_session2)=(7F000001052d62603CXQiw36B103))
-string boolean, optional Tag will return session(s) as a comma-delimited string (test_session1=7F000001052d62603CuULL36B0FB, test_session2=7F000001052d62603CXQiw36B103)

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
[

define_tag:'lp_session_id',
	-description='Retrieves all current Session IDs and returns them as HTML <input>s, URL strings or an array of pairs.',
	-priority='replace',
	-encodenone,
	-optional='xhtml';

	// xhtml?
	local:'serveXHTML' = false;
	if: local_defined:'xhtml' || (var:'_lp_xhtml') === true || $__http_header__->(contains:'xhtml');
		#serveXHTML = true;
	/if;

	// session var names; 
	local:'vars'= (string_findregexp: vars->keys, -find='_SessionTracker_[^\\)]*',-ignorecase);

	// how to output? 
	if: params->(find:'-form')->size > 0 ;
		local:'format'='form';
	else: params->(find:'-url')->size > 0 ;
		local:'format'='url';
	else: params->(find:'-vars')->size > 0 ;
		local:'format'='vars';
	else: params->(find:'-string')->size > 0 ;
		local:'format'='string';
	else;
		local:'format'='array';
	/if;


	// #sessions will be the output, of type (array) 
	local:'sessions' = array;
	local:'session_name' = string;

	iterate: #vars, local:'session_varname';

		if: !#session_varname->(endswith:'_vars') && #session_varname != '_SessionTracker_Result';
			#session_name = (string:#session_varname)->(removeleading:'_SessionTracker_')&;
			// how to output? 
			select: #format;
				case: 'form';
					if: #serveXHTML;
						#sessions->(insert: '<input type="hidden" name="-session" value="'+#session_name+':'+(vars->find: #session_varname)+'" />');
					else; // HTML
						#sessions->(insert: '<input type="hidden" name="-session" value="'+#session_name+':'+(vars->find: #session_varname)+'">');
					/if;
				case: 'url';
					#sessions->(insert: '-session='+(encode_stricturl: #session_name)+':'+(encode_stricturl:(vars->find: #session_varname)));
				case: 'vars';
					#sessions->(insert: #session_varname = (vars->find: #session_varname));
				case: 'string';
					#sessions->(insert: #session_name+'='+(vars->find: #session_varname));
				case; // array
					#sessions->(insert: #session_name = (vars->find: #session_varname));
			/select;
		/if;

	/iterate;

	if: #format=='string';
		return: #sessions->(join:', ');
	/if;
	return: #sessions;

/define_tag;

]

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular