You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 0c160be
Browse filesBrowse the repository at this point in the historyBrowse files
summary: Read the value of one HTTP request header.
6
+
parameters:
7
+
- name: name
8
+
type: TEXT
9
+
required: true
10
+
description: The name of the HTTP header to read.
11
+
---
12
+
13
+
Reads one [HTTP request header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers). Names are case-insensitive: `sqlpage.header('User-Agent')` and `sqlpage.header('user-agent')` read the same value. An absent header returns SQL `NULL`.
14
+
15
+
### Example
16
+
17
+
Log the [`User-Agent`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent) of the browser making the request in the database:
18
+
19
+
```sql
20
+
INSERT INTO user_agent_log (user_agent) VALUES (sqlpage.header('user-agent'));
21
+
```
22
+
23
+
If you need access to all headers at once, use [`sqlpage.headers()`](?function=headers) instead.
'Returns the HTTP request method (GET, POST, etc.) used to access the page.
1
+
---
2
+
icon: http-get
3
+
since: 0.21.0
4
+
category: request-data
5
+
summary: Get the HTTP method, such as GET or POST.
6
+
---
7
+
8
+
Returns the HTTP request method (GET, POST, etc.) used to access the page.
14
9
15
10
## HTTP request methods
16
11
17
12
HTTP request methods (also known as verbs) are used to indicate the desired action to be performed on the identified resource. The most common methods are:
18
13
-**GET**: retrieve information from the server. This is the default method used by browsers when you click on a link.
19
-
- **POST**: submit data to be processed by the server. SQLPage''s [form component](/component.sql?component=form) defaults to POST; a plain HTML form defaults to GET.
14
+
-**POST**: submit data to be processed by the server. SQLPage's [form component](/component.sql?component=form) defaults to POST; a plain HTML form defaults to GET.
20
15
-**PUT**: replace the current representation of the target resource with the request payload. Most commonly used in REST APIs.
21
16
-**DELETE**: remove the target resource.
22
17
-**PATCH**, **HEAD**, **OPTIONS**, **CONNECT**, **TRACE**: less common methods that are used in specific situations.
23
18
24
19
## Require a PUT request
25
20
26
21
```sql
27
-
select ''redirect'' as component,
28
-
''/error?msg=expected+a+PUT+request'' as link
29
-
where sqlpage.request_method() != ''PUT'';
22
+
select'redirect'as component,
23
+
'/error?msg=expected+a+PUT+request'as link
24
+
wheresqlpage.request_method() !='PUT';
30
25
31
26
insert into my_table (column1, column2) values (:value1, :value2);
Copy file name to clipboardExpand all lines: examples/official-site/sqlpage/migrations/08_functions.sql
-91Lines changed: 0 additions & 91 deletions
Original file line number
Diff line number
Diff line change
@@ -12,97 +12,6 @@ CREATE TABLE IF NOT EXISTS sqlpage_function_parameters (
12
12
"description_md"TEXT,
13
13
"type"TEXT
14
14
);
15
-
INSERT INTO sqlpage_functions (
16
-
"name",
17
-
"return_type",
18
-
"introduced_in_version",
19
-
"icon",
20
-
"description_md"
21
-
)
22
-
VALUES (
23
-
'cookie',
24
-
'TEXT',
25
-
'0.7.1',
26
-
'cookie',
27
-
'Reads a [cookie](https://en.wikipedia.org/wiki/HTTP_cookie) with the given name from the request.
28
-
Returns the value of the cookie as text, or NULL if the cookie is not present.
29
-
30
-
Cookies can be set using the [cookie component](documentation.sql?component=cookie#component).
31
-
32
-
### Example
33
-
34
-
#### Set a cookie
35
-
36
-
Set a cookie called `username` to greet the user by name every time they visit the page:
37
-
38
-
```sql
39
-
select ''cookie'' as component, ''username'' as name, :username as value;
40
-
41
-
SELECT ''form'' as component;
42
-
SELECT ''username'' as name, ''text'' as type;
43
-
```
44
-
45
-
#### Read a cookie
46
-
47
-
Read a cookie called `username` and greet the user by name:
48
-
49
-
```sql
50
-
SELECT ''text'' as component,
51
-
''Hello, '' || sqlpage.cookie(''username'') || ''!'' as contents;
52
-
```
53
-
'
54
-
);
55
-
INSERT INTO sqlpage_function_parameters (
56
-
"function",
57
-
"index",
58
-
"name",
59
-
"description_md",
60
-
"type"
61
-
)
62
-
VALUES (
63
-
'cookie',
64
-
1,
65
-
'name',
66
-
'The name of the cookie to read.',
67
-
'TEXT'
68
-
);
69
-
INSERT INTO sqlpage_functions (
70
-
"name",
71
-
"introduced_in_version",
72
-
"icon",
73
-
"description_md"
74
-
)
75
-
VALUES (
76
-
'header',
77
-
'0.7.2',
78
-
'heading',
79
-
'Reads one [HTTP request header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers). Names are case-insensitive: `sqlpage.header(''User-Agent'')` and `sqlpage.header(''user-agent'')` read the same value. An absent header returns SQL `NULL`.
80
-
81
-
### Example
82
-
83
-
Log the [`User-Agent`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent) of the browser making the request in the database:
84
-
85
-
```sql
86
-
INSERT INTO user_agent_log (user_agent) VALUES (sqlpage.header(''user-agent''));
87
-
```
88
-
89
-
If you need access to all headers at once, use [`sqlpage.headers()`](?function=headers) instead.
0 commit comments