title: Validate session cookie value with regex
body: <p>I'm trying to validate a session cookie value with regex, I have done some test, but without any success...could someone write and explain me how to match a non-ASCII character, spaces(\s), comma and semicolon (basically all the forbidden characters of a session value)? Obviously if one of those character is found the entire line is invalid.<br/>
  At this moment my function is this:</p>
  
  <pre><code>session_name("RazorphynSupport");
  
  if(isset($_COOKIE['RazorphynSupport']) &amp;&amp; !is_string($_COOKIE['RazorphynSupport']) || !preg_match('/^[a-z0-9]{26,40}$/',$_COOKIE['RazorphynSupport'])){
      setcookie(session_name(),'invalid',time()-3600);
      //return error
      exit();
  }
  session_start(); 
  
  //Logout
  if($_POST[$_SESSION['token']['act']]=='logout' &amp;&amp; isset($_SESSION['status'])){
      //Logout
  }
  
  //Session Check
  if(isset($_SESSION['time']) &amp;&amp; time()-$_SESSION['time']&lt;=1800)
      $_SESSION['time']=time();
  else if(isset($_SESSION['id']) &amp;&amp; !isset($_SESSION['time']) || isset($_SESSION['time']) &amp;&amp; time()-$_SESSION['time']&gt;1800){
      //Destroy session; return error
  
      exit();
  }
  else if(isset($_SESSION['ip']) &amp;&amp; $_SESSION['ip']!=retrive_ip()){
      //Destroy session; return error
  
      exit();
  }
  else if(!isset($_POST[$_SESSION['token']['act']]) &amp;&amp; !isset($_POST['act']) &amp;&amp; $_POST['act']!='faq_rating' || $_POST['token']!=$_SESSION['token']['faq']){
      //Destroy session; return error
  
      exit();
  }
  </code></pre>
  
  <p>Before the <code>session_start()</code>, but obviously it's wrong.<br/> My problem is that if the session contains any illegal character the session_start function return an error, so to prevent it I would like to check the "integrity" of the cookie<br/>
  <strong>EDIT</strong><br/>
  form firebug cookie tab:</p>
  
  <pre><code>Cookie Name -&gt; RazorphynSupport
  
  Value -&gt; ETpSx-T6VFuIYS3fejyaq0
  </code></pre>
  
  <p>I need to validate <code>ETpSx-T6VFuIYS3fejyaq0</code> (that is a random generated string)</p>