{qs:variable_name:delimiter}

Description

Reads a variable from the current HTTP request and returns its value as text. With a variable name it returns that GET or POST parameter (or, for a request with a JSON body, that key of the body); cookies are never read. Called bare with no name it returns the raw URL query string (everything after the ?, still URL-encoded; POST data is not included). If the value is an array - a name sent with brackets, such as tag[]=news&tag[]=eu - it is joined with the delimiter you pass, or encoded as JSON when you pass none; a name repeated without brackets keeps only its last value. The output depends on the request. The Site module page cache keeps one copy per URL, so ordinary parameters are safe to read; a tracking parameter such as utm_source is cached once per value, and an ad click id such as gclid keeps the page out of the cache. It does NOT escape its output - printing a raw qs value into an HTML page is an XSS risk. Use the sibling qss command, which is exactly safe applied to qs, whenever the value goes into HTML.

Parameters

variable_name optional default (none - bare qs returns the whole query string)

Name of the request variable to read - a GET or POST parameter. Cookies are never read, even where PHP puts them into the request. To read a bracketed field name, give the exact name including the brackets, e.g. aa[n1000_...][con_email_______][]; such a name is looked up literally in the URL query string only (not in POST data), and + in its value stays +. Omit the name entirely (bare qs) to return the whole raw query string instead of one variable.

delimiter optional default (none - arrays are returned as JSON)

Separator used to join the values when the parameter is an array - a name sent with brackets, such as tag[]=news&tag[]=eu. If you omit it, an array value is returned as a JSON-encoded string instead of being joined. A name repeated without brackets (tag=news&tag=eu) is not an array: PHP keeps only the last value. Has no effect on plain scalar values.

Examples

virtual{qs:surname}
ExpectedHavel (for ...?surname=Havel)
The everyday use: read one GET/POST parameter by name. For the URL ...page?surname=Havel this returns the value of surname. On a page with no such parameter it returns an empty string.
test[{qs:this_param_is_never_set_xyz}]
Expected[]
Actual[]
Reading a parameter that is not present in the request yields an empty string - never an error. The brackets here just make the empty result visible.
virtual{qs}
Expectedsurname=Havel&lang=cz (for ...?surname=Havel&lang=cz)
Called with no variable name, qs returns the raw URL query string of the current request - everything after the ? in the URL, still URL-encoded. POST data is not included.
virtual{qs:tag:, }
Expectednews, eu (for ...?tag[]=news&tag[]=eu; without the brackets, ?tag=news&tag=eu gives only eu)
When a parameter is sent as an array (its name ends in []), the second argument is the separator used to join the parts. For ...?tag[]=news&tag[]=eu this returns news, eu. Without the brackets (?tag=news&tag=eu) PHP keeps only the last value, eu.
virtual{qs:tag}
Expected["news","eu"] (for ...?tag[]=news&tag[]=eu)
With no delimiter, an array-valued parameter comes back JSON-encoded rather than joined. Useful when you want to pass the raw list on to another command. For ...?tag[]=news&tag[]=eu the result is the JSON array ["news","eu"].
virtualYou searched for: {qss:hledej}
ExpectedYou searched for: &lt;b&gt; (for ...?hledej=<b> - the tag arrives as text, the browser shows it and does not apply it)
ActualYou searched for:
qs does NOT escape its output, so echoing a raw URL value into a page is an XSS hole. The qss sibling is exactly safe applied to qs: it HTML-encodes the value. Always use qss when the value lands in HTML. For ...?hledej=<b> the angle brackets come back encoded.
virtual{qs:aa[n1000_31][con_email_______][]}
Expectedvisitor@example.org (for ...?aa[n1000_31][con_email_______][]=visitor%40example.org in the URL)
When the variable name itself contains square brackets (an AA form field name), give the exact name including the brackets. qs then looks for that literal key in the URL query string only - a form sent by POST is not found - and returns the first match URL-decoded, except that + stays + (it is not turned into a space).
test[{qss:this_param_is_never_set_xyz}]
Expected[]
Actual[]
The safe variant qss behaves like qs for a missing parameter - an absent value HTML-encodes to nothing - so it too returns an empty string here.