PHP session encoder/decoder written in Go

Overview

php_session_decoder

PHP session encoder/decoder written in Go
Build Status

Installation

Install:

  • The recommended way to install is using gonuts.io:

    nut get yvasiyarov/php_session_decoder for more information, please, go to the http://www.gonuts.io/yvasiyarov/php_session_decoder

  • Using default go get tool:

    go get github.com/yvasiyarov/php_session_decoder

Getting started

Example: load php session data from redis:

if sessionId, err := req.Cookie("frontend"); err == nil {
    if sessionData, err := redis.Get("PHPREDIS_SESSION:" + sessionId.Value); err == nil {
        decoder := php_session_decoder.NewPhpDecoder(sessionData.String())
        if sessionDataDecoded, err := decoder.Decode(); err == nil {
            //Do something with session data  
        }
    } else {
        //Can not load session - it can be expired
    }
}

Example: Encode php session data:

data := make(PhpSession)
data["make some"] = " changes"
encoder := NewPhpEncoder(data)
if result, err := encoder.Encode(); err == nil {
    //Write data to redis/memcached/file/etc
}

Copyright

2013-2014 Yuriy Vasiyarov
2014 Yuriy Vasiyarov, Maksim Naumov.

All rights reserved.

Issues
  • Use bytes.Buffer for string concatenation to improve performance

    Use bytes.Buffer for string concatenation to improve performance

    Ran into a performance issue when trying to serialize large nested data. Changing the code to use a bytes.Buffer for string concatenation helped speed up the performance.

    For example:

    // build up ["VALUES": ["ID_0": 0, ..., "ID_9999": 9999]]
    subData := php_serialize.PhpArray{}
    data := php_serialize.PhpArray{
        "VALUES": subData,
    }
    
    for i := 0; i < 10000; i++ {
        subData["ID_"+strconv.Itoa(i)] = i
    }
    
    startTime := time.Now()
    php_serialize.Serialize(data)
    log.Printf("Time took: %s", time.Since(startTime).String())
    

    Before: ~2s After: < 15ms

    opened by danpurpura 1
  • Fix bug when decoding multiple arrays

    Fix bug when decoding multiple arrays

    The decoder did not recognize trailing semi-colons when decoding arrays. Thus, a session like this:

    array1|a:1:{s:5:\"test1\";b:1;};array2|a:1:{s:5:\"test2\";b:1;};
    

    would result in a PhpSessionData map with the keys array1 and ;array2. This change will optionally read the trailing semi-colon after decoding an array, ensuring that the two keys are array1 and array2.

    opened by adamstep 1
  • Add support for encoding null values

    Add support for encoding null values

    The encoder silently fails when encoding null values. This pull requests adds support for encoding null values, and adds tests to make sure null values are correctly decoded and encoded.

    opened by adamstep 1
  • Your own decode function for object that implements Serializable interface

    Your own decode function for object that implements Serializable interface

    1. Decode objects with Serializable interface and store its raw data;
    2. You can have your own decode function for object that implements Serializable interface;
    3. Improve NULL decoding
    opened by digitalcrab 0
  • Programm Panics

    Programm Panics

    Programm panics then decoding flowing string "|C040000000000000000000:"

    panic: runtime error: makeslice: len out of range [recovered]
        panic: runtime error: makeslice: len out of range
    
    goroutine 29 [running]:
    testing.tRunner.func1(0x8203a0e10)
        /usr/local/Cellar/go/1.5/libexec/src/testing/testing.go:450 +0x171
    github.com/yvasiyarov/php_session_decoder/php_serialize.(*UnSerializer).decodeString(0x82032baa0, 0x2200000022, 0x217000, 0x0, 0x0)
        /Users/gregory/Documents/gospace/src/github.com/yvasiyarov/php_session_decoder/php_serialize/unserialize.go:133 +0xe4
    github.com/yvasiyarov/php_session_decoder/php_serialize.(*UnSerializer).readClassName(0x82032baa0, 0x0, 0x0)
        /Users/gregory/Documents/gospace/src/github.com/yvasiyarov/php_session_decoder/php_serialize/unserialize.go:273 +0x48
    github.com/yvasiyarov/php_session_decoder/php_serialize.(*UnSerializer).decodeSerialized(0x82032baa0, 0x0, 0x0)
        /Users/gregory/Documents/gospace/src/github.com/yvasiyarov/php_session_decoder/php_serialize/unserialize.go:197 +0x42
    github.com/yvasiyarov/php_session_decoder/php_serialize.(*UnSerializer).Decode(0x82032baa0, 0x0, 0x0, 0x0, 0x0)
        /Users/gregory/Documents/gospace/src/github.com/yvasiyarov/php_session_decoder/php_serialize/unserialize.go:66 +0x159
    github.com/yvasiyarov/php_session_decoder.(*PhpDecoder).Decode(0x8203a7eb0, 0x82032baa0, 0x0, 0x0)
        /Users/gregory/Documents/gospace/src/github.com/yvasiyarov/php_session_decoder/decoder.go:41 +0x149
    github.com/yvasiyarov/php_session_decoder.TestFuzzCrashers(0x8203a0e10)
        /Users/gregory/Documents/gospace/src/github.com/yvasiyarov/php_session_decoder/fuzz_test.go:20 +0x1fb
    testing.tRunner(0x8203a0e10, 0x2b4680)
        /usr/local/Cellar/go/1.5/libexec/src/testing/testing.go:456 +0x98
    created by testing.RunTests
        /usr/local/Cellar/go/1.5/libexec/src/testing/testing.go:561 +0x86d
    
    opened by gregory-m 0
Owner
Yuriy Vasiyarov
Yuriy Vasiyarov
Nfc-sun-decoder - A Decoder for NXP 424 DNA SUN (Secure Unique) messages

NFC SUN Decoder A Decoder for NXP 424 DNA SUN (Secure Unique) messages This library makes decoding 424 DNA SUN messages easier. While the 424 DNA chip

Jonathan Bartlett 1 Feb 12, 2022
An optimal, byte-aligned, LZ+RLE hybrid encoder, designed to maximize decoding speed on NMOS 6502 and derived CPUs

TSCrunch TSCrunch is an optimal, byte-aligned, LZ+RLE hybrid encoder, designed to maximize decoding speed on NMOS 6502 and derived CPUs, while keeping

null 26 Jun 10, 2022
Golang binary decoder for mapping data into the structure

binstruct Golang binary decoder to structure Install go get -u github.com/ghostiam/binstruct Examples ZIP decoder PNG decoder Use For struct From file

Vladislav Fursov 54 Jun 10, 2022
BPG decoder for Go (Zero Dependencies)

Go语言QQ群: 102319854, 1055927514 凹语言(凹读音“Wa”)(The Wa Programming Language): https://github.com/wa-lang/wa BPG for Go BPG is defined at: http://bellard.o

chai2010 20 Sep 7, 2020
Sqlyog-password-decoder - Simple decode passwords from .sycs file (SQLyog export connections file)

Decode password: ./sqlyog-password-decoder -str password -action decode Encode p

Maxim Yanin 0 Nov 21, 2021
A simple Slack message tool for the CLI written in Go

heka A simple Slack message tool for the CLI written in Go Report Bug · Request

Josh Murray 4 Jan 16, 2022
COBS implementation in Go (Decoder) and C (Encoder & Decoder) with tests.

COBS Table of Contents About The project COBS Specification Getting Started 3.1. Prerequisites 3.2. Installation 3.3. Roadmap Contributing License Con

Thomas Höhenleitner 2 May 22, 2022
PHP functions implementation to Golang. This package is for the Go beginners who have developed PHP code before. You can use PHP like functions in your app, module etc. when you add this module to your project.

PHP Functions for Golang - phpfuncs PHP functions implementation to Golang. This package is for the Go beginners who have developed PHP code before. Y

Serkan Algur 48 Jun 4, 2022
Pbm - Package ppm implements a Portable Bit Map (PBM) image decoder and encoder written in Go

Package pbm import "github.com/slashformotion/pbm" Package pbm implements a Portable Bit Map (PBM) image decoder and encoder. The supported image col

slashformotion 0 Jan 5, 2022
A Session Encoder For Golang

Session_Encoder Version 1125 Support 3 examples (math,calculator,rank) based on communications between Server and Client via Channel Support basic ses

Cheng Ji 0 Nov 25, 2021
Fast, secure and efficient secure cookie encoder/decoder

Encode and Decode secure cookies This package provides functions to encode and decode secure cookie values. A secure cookie has its value ciphered and

Christophe Meessen 57 May 22, 2022
Package polyline implements a Google Maps Encoding Polyline encoder and decoder.

go-polyline Package polyline implements a Google Maps Encoding Polyline encoder and decoder. Encoding example func ExampleEncodeCoords() { coords :=

Tom Payne 68 Jun 17, 2022
Rich TIFF/BigTIFF/GeoTIFF decoder/encoder for Go (Pure Go/Zero Dependencies)

Go语言QQ群: 102319854, 1055927514 凹语言(凹读音“Wa”)(The Wa Programming Language): https://github.com/wa-lang/wa TIFF for Go Features: Support BigTiff Support

chai2010 42 Jun 2, 2022
WebP decoder and encoder for Go (Zero Dependencies).

Go语言QQ群: 102319854, 1055927514 凹语言(凹读音“Wa”)(The Wa Programming Language): https://github.com/wa-lang/wa webp ██╗ ██╗███████╗██████╗ ██████╗ ██║

chai2010 344 Jun 23, 2022
Fixed width file parser (encoder/decoder) in GO (golang)

Fixed width file parser (encoder/decoder) for GO (golang) This library is using to parse fixed-width table data like: Name Address

Oleg Lobanov 20 Mar 4, 2022
Fast JSON encoder/decoder compatible with encoding/json for Go

Fast JSON encoder/decoder compatible with encoding/json for Go

Masaaki Goshima 1.6k Jun 26, 2022
Pure Go Brotli encoder and decoder

This package is a brotli compressor and decompressor implemented in Go. It was translated from the reference implementation (https://github.com/google

Andy Balholm 406 Jun 24, 2022
asciigrid is a Go package that implements decoder and encoder for the Esri ASCII grid format, also known as ARC/INFO ASCII GRID.

asciigrid asciigrid is a Go package that implements decoder and encoder for the Esri ASCII grid format, also known as ARC/INFO ASCII GRID. Install go

Ahmet Artu Yildirim 0 Oct 16, 2021
Go encoder and decoder for the NetBPM/PNM image formats. Compatible with Go's image packages.

gpnm This package implements an encoder and decoder for PNM image formats. It can be used with Go's image library. It covers all formats as defined by

null 0 Nov 26, 2021
Pure Go encoder/decoder of the QOI image format

QOI - The “Quite OK Image” format for fast, lossless image compression package and small utilities in native Go, quite OK implementation See qoi.h for

Xavier-Frédéric Moulet 56 Jun 3, 2022
BMP image decoder and encoder

bmp Package bmp implements a BMP image decoder and encoder. The BMP specification is at http://www.digicamsoft.com/bmp/bmp.html. Supported BMP feature

Sergey Makinen 0 Nov 28, 2021
goi - The “Quite OK Image” format encoder / decoder for Go.

goi - The “Quite OK Image” format encoder / decoder for Go. QOI - The “Quite OK Image” - is losslessly image format that offering speedup both compres

neguse 14 Mar 3, 2022
ROT13 Encoder/Decoder

ROT-13 Decoder/Encoder Initially written for fun for a CTF Can take a string and encode/decode using ROT13 From Wikipedia: Applying ROT13 to a piece o

JeremiahShafer 0 Dec 29, 2021
Decoder/Encoder for GhostControls Gate Remotes

ghostcontrols Decoder/Encoder for GhostControls Gate Remotes GhostControls makes a variety of automatic gate operators, transmitters and keypads & rec

null 0 Jan 1, 2022
Gosaxml is a streaming XML decoder and encoder, similar in interface to the encoding/xml

gosaxml is a streaming XML decoder and encoder, similar in interface to the encoding/xml, but with a focus on performance, low memory footprint and on

HBT Hamburger Berater Team GmbH 3 Jun 30, 2022
Goridge is high performance PHP-to-Golang codec library which works over native PHP sockets and Golang net/rpc package.

Goridge is high performance PHP-to-Golang codec library which works over native PHP sockets and Golang net/rpc package. The library allows you to call Go service methods from PHP with a minimal footprint, structures and []byte support.

Spiral Scout 1.1k Jun 24, 2022
go-for-php php-to-go

easy-func 项目介绍 使用 golang 来翻译 php 函数。可以看做php函数在golang的映射字典。

null 10 Mar 25, 2022
Nfc-sun-decoder - A Decoder for NXP 424 DNA SUN (Secure Unique) messages

NFC SUN Decoder A Decoder for NXP 424 DNA SUN (Secure Unique) messages This library makes decoding 424 DNA SUN messages easier. While the 424 DNA chip

Jonathan Bartlett 1 Feb 12, 2022