@nano7 and you've tried:
$request->input('ref');
since you are saying that it is ?ref=53saf2 in the URL.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am trying to get a query strings from previous URL in Laravel. My app is similar to Formspree where users can submit a form using and it get send to my website through POST method.
Here is a form hosted on external website
<!-- www.user-website/?ref=53saf2 -->
<form action="https://localhost:8080/s/FORM_KEY" method="POST">
<input type="email" name="email">
<button type="submit">Send</button>
</form>
I want to get capture ?ref=53saf2 in my Laravel controller.
I've tried
$request->headers->get('referer');
URL::previous();
$_SERVER['HTTP_REFERER'];
None of it can capture ?ref. My API route is
Route::post('s/{FORM_KEY}', [Controllers\SubmissionController::class, 'processForm']);
@nano7 Looks like the remote server has its Referrer-Policy set to origin, origin-when-cross-origin or strict-origin-when-cross-origin (the default value), which leaves out the query string in the HTTP headers.
That means your receiving script never has any way of knowing what the query string from the originating page is, under any circumstances, because the remote server strips it before sending the request.
It looks like both your servers are serving pages through plain HTTP, rather than HTTPS. This is fine if it’s just for localhost development, but once in production, you really should make sure everything is HTTPS.
There are three possible ways to remedy the limitation of not having access to the query string, but they all require control over the remote server as well as your own:
<input type="hidden" name="ref" value="<?= $_REQUEST['ref'] ?>" />
no-referrer-when-downgrade. That will include the query string when sending HTTPS→HTTPS requests through secure connections, but not when sending HTTPS→HTTP requests. It will, however, include the query string on HTTP→HTTP requests (if neither server uses HTTPS), where it will be fully exposed, which is why this isn’t really recommendedunsafe-url. This will always include the query string, regardless of security, so everything will be exposed at all timesIf you don’t have control over the remote server to change the form or the server’s Referrer-Policy, then you’re out of luck. It cannot be done.
Please or to participate in this conversation.