Parsing GET request parameters in a URL that contains another URL

Parsing GET request parameters in a URL that contains another URL

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Parsing GET request parameters in a URL that contains another URL

When you encounter a raw $_GET or $_REQUEST value containing what appears to be nested query strings, the behavior is often counterintuitive if you assume standard string parsing rules apply universally. Consider this specific scenario: a user sends a request to test.php?id=http://google.com/?var=234&key=234. When you inspect the output of print_r($_GET['id']), you see http://google.com/?var=234 instead of the full string. The fragment &key=234 is visibly missing from your PHP array.

This isn't a bug in PHP's superglobals; it is a direct consequence of how the HTTP protocol defines query strings and how web servers parse them before data ever reaches your application logic. The URL you are looking at—the one containing http://google.com/?var=234&key=234—is technically a single, flat string that exists in the browser's address bar or the request line. However, the server interprets the first occurrence of the ? character as the delimiter between the path and the query string.

In the example provided, the browser or the client has already processed the outer URL. The part after test.php?id= is being treated as the query value. Inside that value, there is another ?. To a standard HTTP parser running on your server (whether it's Apache, Nginx acting as a reverse proxy, or PHP-FPM), the first ? inside the value http://google.com/?var=234&key=234 acts as a new query string delimiter for the outer request. Consequently, the server strips everything after that inner ? and treats it as part of the outer query string's value, or worse, ignores it entirely depending on how the path is configured.

Wait, that explanation is slightly inaccurate regarding the specific output shown. Let's correct the technical mechanism. The issue arises because the & character inside the nested URL is not being treated as a separator for the outer query string, but rather the parser stops reading the value of id at the first ? it encounters if the path parsing logic is strict about the outer query delimiter. Actually, looking closer at the specific output http://google.com/?var=234, the &key=234 is missing. This usually happens because the web server or the client has truncated the string at the first ? found within the value, treating the rest as if it belongs to a subsequent parameter that doesn't exist, or simply dropping it due to parsing limitations in how the URL is constructed before being sent.

However, the most common cause for this specific truncation behavior—where &key=234 disappears—is that the client (browser) or the proxy server has encoded the inner ? as %3F only if it wasn't already handled. But here we see the raw ?. This suggests the server's URL parser is interpreting the first ? in the value http://google.com/?... as the end of the query string for the current request, effectively discarding everything after it because it doesn't recognize a parameter name following that inner delimiter in the context of the outer request.

To handle this reliably, you must understand that you cannot trust $_GET['id'] to contain arbitrary strings with unencoded special characters if those characters have semantic meaning to the URL parser itself. The safest approach is to ensure that any data you expect to be treated as a literal string within a parameter value is fully URL-encoded by the client before transmission. If you control the client, you should encode the inner ? as %3F and the & as %26.

// Client side (conceptual)
// Bad: ?id=http://google.com/?var=234&key=234
// Good: ?id=http://google.com/%3Fvar=234%26key=234

On the server side, if you are using a framework like Laravel, the Request object handles parsing according to these HTTP standards. If you pass the fully encoded URL, $_GET['id'] will return the complete string including the decoded %3F and %26. You can then manually decode it using urldecode() if you need the original characters back for your logic.

$rawId = $_GET['id']; 
// If encoded: http://google.com/%3Fvar=234%26key=234
$fullUrl = urldecode($rawId); // Now contains the full string

The trade-off here is security and complexity. Allowing nested URLs in GET parameters opens your application to open redirect vulnerabilities and potential parameter injection if you blindly trust that value. You must validate that the decoded string matches a whitelist of allowed domains before using it for redirects or further processing. Relying on the server's default parsing behavior without explicit encoding is brittle and prone to the exact truncation issue seen in your $_GET output.

Our network