The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,'

后端 未结 7 1757
情歌与酒
情歌与酒 2020-11-27 17:12

How to solve :

Warning: session_start() [function.session-start]: The session id is too long or contains illegal characters, valid characters are a-z, A-

相关标签:
7条回答
  • 2020-11-27 17:52

    I suggest to use "more correct" version of the function.

    Several notes:

    1. More correct regular expression (allows characters in the range a-z A-Z 0-9 , (comma) and - (minus)) as described here.
      Regular expression depends on the php ini settings, like described here and here.
    2. Use session name method

    So updated version looks like this:

    <?php
        function my_session_start()
        {
            $sn = session_name();
            if (isset($_COOKIE[$sn])) {
                $sessid = $_COOKIE[$sn];
            } else if (isset($_GET[$sn])) {
                $sessid = $_GET[$sn];
            } else {
                session_start();
                return false;
            }
    
           if (!preg_match('/^[a-zA-Z0-9,\-]{22,40}$/', $sessid)) {
                return false;
            }
            session_start();
    
           return true;
        }
    ?>
    
    0 讨论(0)
提交回复
热议问题