0

I am trying to read user session data from my Magento 1.9.3.7 Redis Session in Rails 5.1.

  1. User logs in
  2. Magento Credis is set to use Zlib to compress the session data (a JSON string).
  3. Magento stores the compressed session data in Redis

Using redis-rb gem:

redis = Redis.new(
        host: ENV['MAGENTO_REDIS_SESSION_HOST'],
        password: ENV['MAGENTO_REDIS_SESSION_PASS'],
        port: ENV['MAGENTO_REDIS_SESSION_PORT'],
        db: ENV['MAGENTO_REDIS_SESSION_DB']
      )
data = redis.hget("sess_123456", "data")
data = data.[4..data.length]
#  => data
#  :gz:x\u0001\xEDWM\x8F\xDB6\u0010\...

json_string = Zlib::Inflate.inflate(data)
# => json_string
# "_secure_cookie_check|s:32:\"4d1234ebebc1234fcf1234fc1234d6da\";core|a:5:{s:23:\"_session_validator_data\";...

Note the |s:<some_number> and a:<some_number> in

I understand that s:32 is the length of the string 4d1234ebebc1234fcf1234fc1234d6da.

Is this a known format? If so, what format is it?

Is there a library I can use to parse this string?

Thanks in advance!

ali
  • 846
  • 2
  • 18
  • 34

1 Answers1

1

Turns out, that format is serialised PHP Session.

  • It's a serialised PHP session since Magento runs on PHP!

Refer to this question

With the session data, you would typically call session_decode in PHP

In case anyone wants to deserialise PHP session in Rails, here are two gems I found:

ali
  • 846
  • 2
  • 18
  • 34