note 116836 added to function.session-id

From: Date: Sun, 08 Mar 2015 06:08:33 +0000
Subject: note 116836 added to function.session-id
Groups: php.notes 
Request: Send a blank email to php-notes+get-201887@lists.php.net to get a copy of this message
It may be good to note that PHP does not allow arbitrary session ids. The session id validation in PHP source is defined in ext/session/session.c in the function php_session_valid_key: https://github.com/php/php-src/blob/master/ext/session/session.c To put it short, a valid session id may consists of digits, letters A to Z (both upper and lower case), comma and dash. Described as a character class, it would be [-,a-zA-Z0-9]. A valid session id may have the length between 1 and 128 characters. To validate session ids, the easiest way to do it use a function like: <?php function session_valid_id($session_id) { return preg_match('/^[-,a-zA-Z0-9]{1,128}$/', $session_id) > 0; } ?> session_id() itself will happily accept invalid session ids, but if you try to start a session using an invalid id, you will get the following error: Warning: session_start(): The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' ---- Server IP: 72.52.91.14 Probable Submitter: 62.78.150.184 ---- Manual Page -- http://php.net/manual/en/function.session-id.php Edit -- https://master.php.net/note/edit/116836 Del: integrated -- https://master.php.net/note/delete/116836/integrated Del: useless -- https://master.php.net/note/delete/116836/useless Del: bad code -- https://master.php.net/note/delete/116836/bad+code Del: spam -- https://master.php.net/note/delete/116836/spam Del: non-english -- https://master.php.net/note/delete/116836/non-english Del: in docs -- https://master.php.net/note/delete/116836/in+docs Del: other reasons-- https://master.php.net/note/delete/116836 Reject -- https://master.php.net/note/reject/116836 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#201887) next »