note 26870 added to function.rawurlencode
| From: | php-general at lists dot php dot net | Date: | Fri, 15 Nov 2002 13:20:58 +0000 |
| Subject: | note 26870 added to function.rawurlencode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-39533@lists.php.net to get a copy of this message | ||
About the ";" reserved character in URLs:
rawurlencode() will encode it with a "%2A" triplet. When used on the path part of a URL,
this will break the usage defined in URL RFCs, that allows specifying additional parameters to
*EACH* element of a path (separated by "/").
So if a path element contains a ";" character (some filesystems allow it, but this is not
recommanded) as part of a directory name, this character must be encoded so that it won't be
mixed with a parameter extension.
This mapping is allowed on URLs that use a hierarchical scheme (HTTP, HTTPS, FTP, FILE, ...), so
that each path element prefixed by "/" can have additional navigational parameters such as
authorization strings or semantic parameters.
The generic format of a path element may include path elements such as:
"/." or "/.." or "/.specialname" or "/regularname"
Each part may be followed by a ";" and other parameters separated by ";". These
parameters can be eithger ordered or unordered. Unordered parameters have a symbolic name separated
from their value with an equal sign.
Do not mix path element parameters with a query string: these parameters are directly attached to
the individual path element, and this makes a difference when this path element is not the last one
of the URL. These parameters are part of the resource name (unlike the query string), and the
semantic of "." and ".." apply to the full path element with its parameters, so
that:
"/subdir1/subdir2/page.html;charset=UTF-8/../index.html"
will resolve to "/subdir1/index.html".
Note that:
"/subdir1/subdir2/page.html;charset=UTF-8"
designates a DISTINCT resource name from:
"/subdir1/subdir2/page.html"
It does not necessarily involves a query, and so it can be cached by default (unlike URLs that
contain a query string).
When using path element parameters, their optional name and required value must be
rawurlencode()'d separately before inserting ";" and "=" parameters and
creating the path elements that will be imploded in the full path.
The consequence is that you MUST not urlencode() or rawurlencode individual path elements, without
first parsing them:
- first explode the path into its path lements separated by "/"
- then explode each path element in their name and parameters separated by ";" characters
- then split path element parameters that contain a "=" sign into a name/value pair.
- make sure that unordered path paremeters (that have been cut according to "=" into a
pair) are specified *after* ordered parameters (including the main path element name) in each path
element, and that no two unordered parameters have the same name (this restriction does not occur on
unordered, unnamed parameters which only supply a value).
- finally you can interpret rawurlencoded names and values that constitute each path element.
Note also that some non-compliant HTTP servers consider that named parameters are ordered, and
don't add a semantic to the ";" and "=" used to break up the list of path
element parameters. On client agents, when validating URLs, it's best then not to try to
interpret this list, and you should just split the main part of a path element and the parameters
list by isolating the first ";" that introduces this list. However, the encoded parameter
list cannot include any "/" parameter.
Caveats: note that path element parameters (introduced by ";") may be used on upper levels
of a hierarchic URL, even before the final document name and its query parameters. When building
lists of URLs, you should not separate URLs blindly with a ";" separator, as each URL may
include a ";" character, in their path part (the ";" character cannot ocur
safely in a query string). In that case, use a surrounding pair such as "<>" or
quotes to enclose each URL in such a list.
--
http://www.php.net/manual/en/function.rawurlencode.php
http://master.php.net/manage/user-notes.php?action=edit+26870
http://master.php.net/manage/user-notes.php?action=delete+26870
http://master.php.net/manage/user-notes.php?action=reject+26870