I am trying to update a parameter in my referer url:
$referer = $request->headers->get('referer');
For example, $referer
is an url whith two parameter:
string(96) "http://<my_url>/web/app_dev.php/urlpart/?param1=value1¶m2=value2"
I'd like to easyly replace param1=value1
by param1=updatedvalue1
for example with another one.
I know we can do this with twig
with the current request url:
{{ path(app.request.attributes.get('_route'),
app.request.query.all|merge({'sort': 'address'})) }}
Is it possible to do the same thing in a Symfony 2 controller to update the referer?
I have found a solution with preg_replace
function in PHP
, I hope there is a better way to do it seems ugly, I am trying to find a better solution, any help will be apprecied!
$referer = preg_replace('/([?&])(param1)=\w+(&|$)/', '', $referer);
$referer = preg_replace('/(param2)=\w+(&|$)/', '', $referer);
Thank you for your help !