jsgetcookie
Code (php)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
* requestVars.js
*
* This file contains functions to access the content of cookies
* and GET parameters easily for javascript.
* They are inspired by their PHP equivalent.
*
* This source file is subject to version 2.1 of the GNU Lesser
* General Public License (LPGL), found in the file LICENSE that is
* included with this package, and is also available at
* http://www.gnu.org/copyleft/lesser.html.
* @package Javascript
*
* @author Dieter Raber <[email protected]>
* @copyright 2004-12-27
* @version 1.0
* @license http://www.gnu.org/copyleft/lesser.html
*
*/
/**
* TOC
*
* - readGet
* - readCookies
*/
/**
* _GET is the equivalent to PHP's $_GET
* An associative array of variables passed to the current script
* via the HTTP GET method. This function is called onload.
* This means that as soon as this file is included _GET will be available
*
* example:
* If the curent URL contains GET parameters e.g.
* myurl.htm?color1=red&color2=blue
* then _GET['color1'] will contain 'red'
* and _GET['color2'] will contain 'blue'
*/
function readGet()
{
var _GET = new Array();
var uriStr = window.location.href.replace(/&/g, '&');
var paraArr, paraSplit;
if (uriStr.indexOf('?') > -1)
{
var uriArr = uriStr.split('?');
var paraStr = uriArr[1];
}
else
{
return _GET;
}
if (paraStr.indexOf('&') > -1)
{
paraArr = paraStr.split('&');
}
else
{
paraArr = new Array(paraStr)
}
for(var i = 0; i < paraArr.length; i++)
{
paraArr[i] = paraArr[i].indexOf('=') > -1
? paraArr[i]
: paraArr[i] + '=';
paraSplit = paraArr[i].split('=')
_GET[paraSplit[0]] = decodeURI(paraSplit[1].replace(/\+/g, ' '));
}
return _GET;
}
var _GET = readGet();
/**
* _COOKIE is the equivalent to PHP's $_COOKIE
* An associative array of variables passed to the current script
* via the HTTP COOKIE method. This function is called onload.
* This means that as soon as this file is included _COOKIE will be available
*
* example:
* This function is called onload
* If two cookies are set, e.g.
* foo=yellow and bar=pink
* then _COOKIE['foo'] will contain 'yellow'
* and _COOKIE['bar'] will contain 'pink'
*/
function readCookie()
{
var _COOKIE = new Array()
var cookieStr = document.cookie ? document.cookie : '';
var cookieSplit, cookieKey;
if(cookieStr)
{
cookieStr = cookieStr.replace(/; /, ';')
var cookieArr = cookieStr.indexOf(';') > -1
? cookieStr.split(';')
: new Array(document.cookie);
for(var i = 0; i < cookieArr.length; i++)
{
cookieArr[i].indexOf('=') > -1 ? cookieArr[i] : cookieArr[i] + '=';
cookieSplit = cookieArr[i].split('=');
cookieKey = cookieSplit[0].charAt(0) == ' '
? cookieSplit[0].substring(1, cookieSplit[0].length)
: cookieSplit[0];
_COOKIE[cookieKey] = cookieSplit[1].replace(/\+/g, ' ');
}
}
return _COOKIE
}
var _COOKIE = readCookie();
* requestVars.js
*
* This file contains functions to access the content of cookies
* and GET parameters easily for javascript.
* They are inspired by their PHP equivalent.
*
* This source file is subject to version 2.1 of the GNU Lesser
* General Public License (LPGL), found in the file LICENSE that is
* included with this package, and is also available at
* http://www.gnu.org/copyleft/lesser.html.
* @package Javascript
*
* @author Dieter Raber <[email protected]>
* @copyright 2004-12-27
* @version 1.0
* @license http://www.gnu.org/copyleft/lesser.html
*
*/
/**
* TOC
*
* - readGet
* - readCookies
*/
/**
* _GET is the equivalent to PHP's $_GET
* An associative array of variables passed to the current script
* via the HTTP GET method. This function is called onload.
* This means that as soon as this file is included _GET will be available
*
* example:
* If the curent URL contains GET parameters e.g.
* myurl.htm?color1=red&color2=blue
* then _GET['color1'] will contain 'red'
* and _GET['color2'] will contain 'blue'
*/
function readGet()
{
var _GET = new Array();
var uriStr = window.location.href.replace(/&/g, '&');
var paraArr, paraSplit;
if (uriStr.indexOf('?') > -1)
{
var uriArr = uriStr.split('?');
var paraStr = uriArr[1];
}
else
{
return _GET;
}
if (paraStr.indexOf('&') > -1)
{
paraArr = paraStr.split('&');
}
else
{
paraArr = new Array(paraStr)
}
for(var i = 0; i < paraArr.length; i++)
{
paraArr[i] = paraArr[i].indexOf('=') > -1
? paraArr[i]
: paraArr[i] + '=';
paraSplit = paraArr[i].split('=')
_GET[paraSplit[0]] = decodeURI(paraSplit[1].replace(/\+/g, ' '));
}
return _GET;
}
var _GET = readGet();
/**
* _COOKIE is the equivalent to PHP's $_COOKIE
* An associative array of variables passed to the current script
* via the HTTP COOKIE method. This function is called onload.
* This means that as soon as this file is included _COOKIE will be available
*
* example:
* This function is called onload
* If two cookies are set, e.g.
* foo=yellow and bar=pink
* then _COOKIE['foo'] will contain 'yellow'
* and _COOKIE['bar'] will contain 'pink'
*/
function readCookie()
{
var _COOKIE = new Array()
var cookieStr = document.cookie ? document.cookie : '';
var cookieSplit, cookieKey;
if(cookieStr)
{
cookieStr = cookieStr.replace(/; /, ';')
var cookieArr = cookieStr.indexOf(';') > -1
? cookieStr.split(';')
: new Array(document.cookie);
for(var i = 0; i < cookieArr.length; i++)
{
cookieArr[i].indexOf('=') > -1 ? cookieArr[i] : cookieArr[i] + '=';
cookieSplit = cookieArr[i].split('=');
cookieKey = cookieSplit[0].charAt(0) == ' '
? cookieSplit[0].substring(1, cookieSplit[0].length)
: cookieSplit[0];
_COOKIE[cookieKey] = cookieSplit[1].replace(/\+/g, ' ');
}
}
return _COOKIE
}
var _COOKIE = readCookie();