Skip to content

Instantly share code, notes, and snippets.

@uintdev
Last active April 6, 2017 19:40
Show Gist options
  • Save uintdev/b30cd56023eac5c4ab32175163fc8b6c to your computer and use it in GitHub Desktop.
Save uintdev/b30cd56023eac5c4ab32175163fc8b6c to your computer and use it in GitHub Desktop.
PHP Session ID Format Verification
<?php
# INFO ABOUT PHP SESSION ID COOKIE
define('SERVER_SESS_ID', session_id());
define('SERVER_SESS_CHAR', '26');
# PHP SESSION ID FORMAT VERIFICATION
if(isset($_COOKIE[SERVER_SESS_ID])) {
if (!preg_match('/^[a-z0-9]{'.SERVER_SESS_CHAR.'}$/', $_COOKIE[SERVER_SESS_ID])) {
setrawcookie(SERVER_SESS_ID, '', 1, '/', null, null, true);
exit('session validation error - try refreshing');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment