Super-simple library for secure PHP session handling
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Super-simple library for secure PHP session handling
Current version: 1.2
License: MIT License


  1. PHP 5.6+


  1. Save secsesh.php on your server. You can rename it.
  2. Configure the options at the top of the file.
  3. Add this to the top of all your files: require 'secsesh.php';
  4. All done!


  1. Fingerprint-checking to prevent session hijacking
  2. Single-file library
  3. Idle-time timeouts
  4. Easy configuration and implementation


SecSesh creates a fingerprint when the session is initialized and cross-checks against this each time a page is accessed. If the fingerprint doesn't match, the session is destroyed. The fingerprint is a combination of the user's User Agent and IP address.



This is what initializes the session. It creates the fingerprint and starts the idle timeout timer. It should be called after session_start(). It takes no arguments.


This is destroys a session. It takes no arguments.


This checks whether a session is active. It returns true if the session hasn't timed out and the fingerprint hasn't changed. Takes no arguments.


Usage examples: see

Misc. Considerations

  1. You should be using SSL, because this library won't provide you much protection otherwise, except maybe some against session hijacking through the fingerprinting technique.


  • v0.1: Initial version
  • v0.2: Renamed variables
  • v1.0: Rewritten to use \secSesh\ namespace
  • v1.1: Removed prefix from function names
  • v1.2: Bugfixes

Report Bugs

Create an Issue or tweet to me at @rahuldottech