readvars - read URL-encoded variables


<readvars $srcvarnames [$destvarnames] $urldata>

Vortex variables are automatically imported from the CGI query string (QUERY_STRING environment variable) on script start, so normally no special parsing is needed. However, in cases where different or custom URL-encoded data must be parsed for values, the <readvars> function can be used. readvars assigns Vortex variables from the URL-encoded string(s) in $urldata.

If the $srcvarnames parameter is non-empty, then only those $urldata variables named as values of $srcvarnames will be read; the default ($srcvarnames empty) is to assign all variables in $urldata. This prevents a script's reserved variables from being overwritten by a rogue or unknown $urldata string.

In version 6.00.1283296000 20100831 and later, an optional $destvarnames argument may be given. This is a list of Vortex variable names to assign the parallel $srcvarnames query string variables to. It provides a way to parse an arbitrary or changing list of query string variable names into a fixed set of known Vortex variables.

The readvars function returns the number of values that were URL-decoded and assigned from $urldata. $srcvarnames is the list of valid $urldata variable names; $destvarnames is the optional list of Vortex variables to assign to.


<$str = "Don't change me">
<$data = "x=123&str=hello+there&x=5">    <!-- e.g. from user -- >
<readvars "x" $data>

$x would have the values 123 and 5, but $str would still be "Don't change me" because "str" was not one of the variable names specified to readvars.

The readvars function was added Nov. 14 1996. Full binary data is not yet supported. If a variable named in the $urldata parameter is unknown in the script (i.e. is not explicitly referenced elsewhere), it will not be assigned since it doesn't exist. There is as yet no equivalent writevars function; use fmt (here) with the %U format.

fmt "%U", fmt "%!U", getvar, setvar

Copyright © Thunderstone Software     Last updated: Oct 24 2023
Copyright © 2023 Thunderstone Software LLC. All rights reserved.