I use the “Current url” function to get the current link when user changing page language
$uri = explode('&', $_SERVER['REQUEST_URI']);
$uri = $uri[0];
$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$uri : "http://".$_SERVER['SERVER_NAME'].$uri;
Problem is, when I have a link like this:
http://127.0.0.1/index.php?id=shop&id2=13&lang=lt
id2, of course, disappears. What can I do about this? It is possible if id2 is set to use explode with a second & or something like this?
You can use the parse_url function, here is an example:
I did not see in your code where you get the script’s filename, so I used
$_SERVER['SCRIPT_NAME'].Edit: My mistake, I did not see that you need to manipulate / remove the last
$_GETparameter. Here is an example on how to do that using a method similar to the above in conjunction with parse_str. Note that this method will work regardless of the location of thelangparameter, it does not have to be the last one in the query string.Thanks to @Yzmir Ramirez for an improvement in the second version that eliminates the extraneous call to
parse_url.