What you're inquiring about are the appendages that make up the query section of a URI:
<scheme>://<authority><path>?<query>
foo://example.com:8042/over/there?name=ferret#nose
\_/ \______________/\_________/ \_________/ \__/
| | | | |
scheme authority path query fragment
Quoted from: 3. Syntax Components (RFC 3986) https://www.rfc-editor.org/rfc/rfc3986#page-16
To include an optional <query>
in an existing
<scheme>://<authority><path>
, you would need a helper function like the one below. For simplicity, we will not be including the
<fragment>
portion in this example:
function href_append_query($href)
{
$query = isset($_SERVER['QUERY_STRING'])
? '?' . $_SERVER['QUERY_STRING']
: ''
;
$query = strtr(
$query, [
'"' => '"',
"'" => ''',
'&' => '&'
]
);
return $href . $query;
}
Here's how you can use it:
<a href="<?=href_append_query('http://step2.com/')?>Some link</a>
This simple function ensures that the QUERY_STRING
, which can be accessed through $_SERVER
Docs, is properly encoded for HTML output.