I am working on multi store

Store > Configuration > General > Web > Session Validation Settings > Use SID on Storefront is set to "Yes" allow customer to stay logged in when switching between different stores.

enter image description here

However I am not getting SID in my front end URL. Is there any way to get SID pragmatically and append to front end URL.

2 Answers 2


I think you can get get Session from getSessionId() Using


How session is appended to url you can refer to createUrl() in


It appends throught _prepareSessionUrl()

 * Check and add session id to URL
 * @param string $url
 * @return \Magento\Framework\UrlInterface
protected function _prepareSessionUrl($url)
    if (!$this->getUseSession()) {
        return $this;
    $sessionId = $this->_session->getSessionIdForHost($url);
    if ($this->_sidResolver->getUseSessionVar() && !$sessionId) {
        $this->setQueryParam('___SID', $this->_isSecure() ? 'S' : 'U');
    } elseif ($sessionId) {
        $this->setQueryParam($this->_sidResolver->getSessionIdQueryParam($this->_session), $sessionId);
    return $this;
  • I accepted it but I can't add up vote due to my less reputation. May 15, 2017 at 10:57
  • It is not accepted Waseem. You need to click the accept Icon.
    – Priyank
    May 15, 2017 at 11:07
  • ok clicked on accept icon... May 15, 2017 at 11:52

Take a look at the Magento\Framework\Session\SidResolver. You can add it in DI and get current SID using the method getSid.

You can debug why your session id parameter is mised from the url inside the Magento\Framework\Url class in the useSessionIdForUrl method, where the magento checks is SID should be added to the url or not:

 * Check and return use SID for URL
 * @param bool $secure
 * @return bool
public function useSessionIdForUrl($secure = false)
    $key = 'use_session_id_for_url_' . (int)$secure;
    if (is_null($this->getData($key))) {
        $httpHost = $this->_request->getHttpHost();
        $urlHost = parse_url($this->_getScope()->getBaseUrl(UrlInterface::URL_TYPE_LINK, $secure), PHP_URL_HOST);

        if ($httpHost != $urlHost) {
            $this->setData($key, true);
        } else {
            $this->setData($key, false);
    return $this->getData($key);

SID appears in a request only when you go from one host to other host.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.