So just a quick thought and I understand that there are millions of ways around this 'problem' but I was wondering if there is a character or format for both initiating and separating GET parameters. Let me explain:
I am redirecting the user to a link defined as a variable but adding on a parameter at the end like so:
Header("Location: ".$link."&err=1");
The problem is, some of these links ($link) will contain GET params and some will not. If the link does not already contain GET parameters, '&' will not work as an initiator.
Header("Location: page&err=1");
And if the link does already contain parameters, '?' will not work as a separating character.
Header("Location: page?val=123?err=1");
So again, I know there are many ways around this and I'm not lookign for someone to code a simple check for me but I'm curious about the link formatting aspect and I can't find anything through my own research. I'm honestly expecting that the answer is 'not possible' but I'm intrigued enough to ask now, thanks.
CodePudding user response:
No.
?
starts the query string.
&
and ;
separate key=value pairs in application/x-www-form-urlencoded data which is the format most back ends expect. (;
hasn't got as good a level of support).
CodePudding user response:
I can't comment yet, because I don't have enough rep. Since you tagged this as PHP, you could look into https://www.php.net/manual/en/function.parse-str.php and https://www.php.net/manual/en/function.parse-url.php and related friends. HTH
CodePudding user response:
Will parse_url() not work?
Specifically parse_url($url, PHP_URL_QUERY);
http_build_query() could also be useful