In my test.php I would like to provide a link back to the production script index.php, passing the same GET-parameters:
foreach ($_GET as $key => $val) {
$get .= "&$key=$val";
}
# this one is wrong - I want to replace just the first "&"
$get = str_replace("&", "?", $get);
echo '<p>You are viewing the test version.</p>
<p><a href="/index.php' . $get .
'">Return to production version</a></p>';
How do I replace just the 1st char in the $get string?
Or maybe there is a nicer way to create a “self-link”?
You should look at
$_SERVER['QUERY_STRING'], which contains the query string from the request, except for the first?charater.So, for instance, if you were to go to http://example.com/page.php?var1=val1&var2=val2, the contents of
$_SERVER['QUERY_STRING']would bevar1=val1&var2=val2Also, to replace the first character of the string, you can simply use: