backported session fix from pull request #1898 to stable 45 to fix #1049

Btw, i tried to avoid the OC_Hook changes but everytime i save the file this lines get changed. Maybe encoding problem? Anyway, shouldnt matter since nothing is changed.

@karlitschek @DeepDiver1975