Php 更改语言时,url必须固定

Php 更改语言时,url必须固定,php,Php,在我的应用程序中,我有一个生成url的问题,我知道您是否有办法解决这个问题 多谢各位 正常url 当我更改语言时,我对url没有问题 http://localhost/test/boutique/index.php http://localhost/test/boutique/index.php?language=fr http://localhost/test/boutique/index.php?language=en 我可以在索引页面中选择一种语言,然后继续产品,没问题 http://l

在我的应用程序中,我有一个生成url的问题,我知道您是否有办法解决这个问题

多谢各位

正常url

当我更改语言时,我对url没有问题

http://localhost/test/boutique/index.php
http://localhost/test/boutique/index.php?language=fr
http://localhost/test/boutique/index.php?language=en
我可以在索引页面中选择一种语言,然后继续产品,没问题

http://localhost/test/boutique/index.php?Products&Description&products_id=1
但是如果我在一个产品中,并且我改变了语言,那么问题就会出现在url中=&

localhost/test/boutique/index.php?Products=&Description=&products_id=1&language=en
我认为有url问题产生,但没有发生在导航。问题是,只有当我更改页面内的语言时

没有关于链接的代码

  public static function link($page, $parameters = null, $add_session_id = true, $search_engine_safe = true)  {

      $page = HTML::sanitize($page);

      $site = $req_site = static::$site;

      if ((strpos($page, '/') !== false) && (preg_match('/^([A-Z][A-Za-z0-9-_]*)\/(.*)$/', $page, $matches) === 1) && OSCOM::siteExists($matches[1], false)) {
          $req_site = $matches[1];
          $page = $matches[2];
      }

      if (!is_bool($add_session_id)) {
        $add_session_id = true;
      }

      if (!is_bool($search_engine_safe)) {
        $search_engine_safe = true;
      }

      if (($add_session_id === true) && ($site !== $req_site)) {
        $add_session_id = false;
      }

      $link = static::getConfig('http_server', $req_site) . static::getConfig('http_path', $req_site) . $page;

      if (!empty($parameters)) {
        $p = HTML::sanitize($parameters);

         $p = str_replace([
                          "\\", // apps
                          '{', // product attributes
                          '}' // product attributes
                          ], [
                            '%5C',
                            '%7B',
                            '%7D'
                          ], $p);


        $link .= '?' . $p;
        $separator = '&';
      } else {
        $separator = '?';
      }

      while((substr($link, -1) == '&') || (substr($link, -1) == '?')) {
        $link = substr($link, 0, -1);
      }

// Add the session ID when moving from different HTTP and HTTPS servers, or when SID is defined
      if (($add_session_id === true) && Registry::exists('Session')) {
        $OSCOM_Session = Registry::get('Session');

        if ($OSCOM_Session->hasStarted() && ($OSCOM_Session->isForceCookies() === false)) {
          if ((strlen(SID) > 0) || (((HTTP::getRequestType() == 'NONSSL') && (parse_url(static::getConfig('http_server', $req_site), PHP_URL_SCHEME) == 'https')) || ((HTTP::getRequestType() == 'SSL') && (parse_url(static::getConfig('http_server', $req_site), PHP_URL_SCHEME) == 'http')))) {
            $link .= $separator . HTML::sanitize(session_name() . '=' . session_id());
          }
        }
      }

      while(strpos($link, '&&') !== false) {
        $link = str_replace('&&', '&', $link);
      }

      if ($search_engine_safe === true && defined('SEARCH_ENGINE_FRIENDLY_URLS') && (SEARCH_ENGINE_FRIENDLY_URLS == 'true' && SEFU::start()) && static::getSite() != 'ClicShoppingAdmin') {
//        $link = str_replace(['?', '&', '='], '/', $link);
        $link = str_replace(['?', '&', '='], ['/', '/', ','], $link);
      }

      return $link;
    }


   public static function link($url, $element, $parameters = null) {
      return '<a href="' . $url . '"' . (!empty($parameters) ? ' ' . $parameters : '') . '>' . $element . '</a>';
    }






public function getFlag() {
      if (!isset($_GET['Checkout'])) {
        $content = '';

        $get_params = [];

        foreach ( $_GET as $key => $value ) {
          if (($key != 'language') && ($key != Registry::get('Session')->getName()) && ($key != 'x') && ($key != 'y')) {
            $get_params[] = $key . '=' . $value;
          }
        }

        $get_params = implode($get_params, '&');


        if ( !empty($get_params) ) {
          $get_params .= '&';
        }

        foreach ($this->getAll() as $value) {
          $content .= ' ' . HTML::link(OSCOM::link('index.php', $get_params . 'language=' . $value['code']), $this->getImage($value['code'])) . ' ';
        }
      }

      return $content;
    }

你的问题似乎在这里:

$get_params[] = $key . '=' . $value;
也许可以试试:

$get_params[] = ($value) ? "$key=$value" : $key;
(如果值为空,则不要附加等号和值,只添加键)


您应该阅读@Patrick Q的评论。

index.php?Products&Description&Products\u id=1
这不是正确的查询字符串格式
index.php?Products=&Description=&Products\u id=1&language=en
这是正确的查询字符串格式。你可能想调查一下,然后。
$get_params[] = ($value) ? "$key=$value" : $key;