phpmultilingualgetparameter

PHP Multilanguage GET parameters


I'm building multi-language support for PHP page. Let's say I have a page url:

http://mypage.php?user=eric&city=newyork

What is the common solution to switch between get parameters lang=en and lang=es while keeping the get parameters already in the url?


Solution

  • A useful script that returns the relative URL of the current page with the current "GET data".

    <?php 
    function getCurrentURL() { 
        $currentURL = basename($_SERVER["PHP_SELF"]); 
        $i = 0; 
        foreach($_GET as $key => $value) { 
            $i++; 
            if($i == 1) { $currentURL .= "?"; } 
            else { $currentURL .= "&amp;"; } 
            $currentURL .= $key."=".$value; 
        } 
        return $currentURL; 
    } 
    ?> 
    

    modify it and concatenate your language parameters accordingly