In header('Location: ?cart');, the question mark starts the URL’s query string. The browser keeps the current path and requests it with cart as a query parameter. It does not tell PHP to open a file named cart; your application must decide what that parameter means.
What does the question mark do?
A URL has a path and may have a query component. The ? separates them. In ?cart, there is no new path before the question mark, so the relative URL refers to the current path with a query string containing the parameter name cart. The exact destination depends on the current URL and the site’s routing rules; it is not necessarily index.php.
The word cart is query data, not a filename. The browser requests a URL, the server and application routing select the PHP script, and that script’s code decides whether to include or render a cart template.
How does PHP use cart?
PHP makes URL query parameters available in the $_GET associative array. The PHP manual describes it as variables passed to the current script through URL parameters, and notes that it is populated when a query string is present even if the request uses POST. Thus, a form can submit using POST while a query parameter in its URL still indicates which action the controller should handle. PHP manual: $_GET.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →#1 Best Overall
A controller could test whether the parameter exists and then choose its own behavior:
if (isset($_GET['cart'])) {
// Select the cart action or render the cart template.
}
In the SitePoint discussion’s specific PHP example, isset($_GET['cart']) is true and dumping the value shows an empty string. That example illustrates a bare parameter; it should not be taken as a universal description of every repeated or unusual query-string form. The application must also decide whether presence alone is enough or whether it should check a particular value.
Rank #2
How does ?cart change the URL?
The relative target ?cart replaces the query component with cart while retaining the current path. If the current page URL is /shop.php?step=payment, the resulting target is /shop.php?cart. The request path remains /shop.php; the application then interprets the new query string.
Form actions can affect which URL is submitted. In the linked discussion’s scenario, an empty action submits to the current URL and retains its query string, whereas action="?" submits to the same path with a blank query component, clearing existing query parameters. The browser-resolved form URL and any application routing determine the actual target. SitePoint discussion of form action and query strings.
Free tools Windows power users keep installed
One-click scans. No signup required.
What should follow a PHP redirect?
header() sends a raw HTTP response header. A Location: header tells the browser to redirect; PHP normally sends status 302 unless an applicable 201 or 3xx status has already been set. PHP requires that header() run before output, including accidental whitespace. After redirecting, stop the current request’s application logic, commonly with exit:
header('Location: ?cart');
exit;
See the PHP manual entry for header() for the behavior and status-code details.
Quick Recap
Rank #4
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




