php - Session start validation -


i have function:

public static function sessionstart() {     try {         if (ini_get('session.use_cookies') && isset($_cookie['phpsessid'])) {             $sessid = $_cookie['phpsessid'];         } elseif (!ini_get('session.use_only_cookies') && isset($_get['phpsessid'])) {             $sessid = $_get['phpsessid'];         } else {             session_start();             return false;         }          if (preg_match('/[^a-za-z0-9\-]{32}/i', $sessid)) {             return false;         }         session_start();          return true;     } catch (exception $ex) {         return false;     } } 

however, in cases, session_start still throws warning. how validate session id never warnings? problem started creep in when changed php version 5.3 5.6.

warning:

the session id long or contains illegal characters, valid characters a-z, a-z, 0-9 , '-,'

one solution use php error control operator:

@session_start(); 

if want validate started properly, return bool that:

return @session_start(); 

(as stated in documentation:)

this function returns true if session started, otherwise false.

it appears function checking regex incorrect, i've updated below:

!preg_match('/^[a-z0-9\-]{32}$/i', $sess) 

you can see results here.


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -