Last active
April 6, 2017 19:40
-
-
Save uintdev/b30cd56023eac5c4ab32175163fc8b6c to your computer and use it in GitHub Desktop.
PHP Session ID Format Verification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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