Skip to content

Instantly share code, notes, and snippets.

@Checksum
Created June 9, 2012 08:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Checksum/2900087 to your computer and use it in GitHub Desktop.
Save Checksum/2900087 to your computer and use it in GitHub Desktop.
Stronger PHP Session IDs
<?php
// Generating stronger PHP session IDs
// Change from default PHPSESSID
ini_set('session.name','my_cookie');
// Use only cookies to prevent session ID hijacking
ini_set('session.use_cookies', 'true');
ini_set('session.use_only_cookies', 'true');
// By default, ID is generated using MD5. Make it longer and more secure
ini_set('session.hash_function', 'sha256');
// Get random bytes to increase entropy
ini_set('session.entropy_file', '/dev/urandom');
ini_set('session.entropy_length', '32');
session_start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment