I have a solution for storing data based on a database. Works great! However, I have a problem storing a specific data type.
I have an application that uses CSRF tokens. When a form is created, it will create a token for that form. A token is a hashed (sha256) value of various types of values. One copy goes to the form, and the other copy is stored in sessions. When submitting the form, it compares the tokens to make sure they match.
Below is an example of a destruct function that updates db with new data
UPDATE session_manager SET variables= :variables WHERE 1=1 AND id = :id array(2) { [":variables"]=> string(152) "a:1:{s:4:"CSRF";a:1:{s:8:"register";a:2:{s:5:"token";s:64:"e749603241dec1911ef3a40d98b2f5185d389434060483297394b504cc904ede";s:4:"time";i:1443456816;}}}" [":id"]=> string(2) "49" }
The update statement works fine and works fine. This is the problem that I have, the data is being updated, but the value of the "token" that you can see in the above data is not the same value in db which is lower (this is a binary data load):
a:1:{s:4:"CSRF";a:1:{s:8:"register";a:2:{s:5:"token";s:64:"b48fc79fc2f51eff765c05476895238a42d9d45b2c1aeb7c6e4582d0381b7f4f";s:4:"time";i:1443456817;}}}
It would seem that mysql is changing the meaning, and I cannot let my life determine the problem. The solutions I tried include:
- serialization
- json_encode
- base64
Change the db encoding and what not. Tried different types of fields in db, for example TEXT, Longtext and BLOB. This does not seem to work for me :(
Here is sql for db
CREATE TABLE session_manager( id BIGINT(11) PRIMARY KEY AUTO_INCREMENT NOT NULL, session_id VARCHAR(200), user_agent TINYTEXT NOT NULL, variables BLOB NOT NULL, initial_time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, regenerate_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL );
Any reasons to keep in mind?