October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

What Does `?cart` Mean in a PHP `header(‘Location: …’)` Redirect?

In a PHP Location redirect, `?cart` keeps the current path and supplies a query parameter. Your controller—not the question mark—decides what happens next.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.