Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9189651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:17:01+00:00 2026-06-17T20:17:01+00:00

I was looking through the code for Zend_Session to try and get a better

  • 0

I was looking through the code for Zend_Session to try and get a better understanding of how to implement session starting. Within the code, they do something that I don’t quite understand.

$hashBitsPerChar = ini_get('session.hash_bits_per_character');          
if (!$hashBitsPerChar) {
    $hashBitsPerChar = 5;
}           
switch($hashBitsPerChar) {
    case 4: $pattern = '^[0-9a-f]*$'; break;
    case 5: $pattern = '^[0-9a-v]*$'; break;
    case 6: $pattern = '^[0-9a-zA-Z-,]*$'; break;
}           
if(!preg_match('#'.$pattern.'#', $id)){             
    session_id(md5(session_id()));              
    $regenerateId = true;
}

What I’m having difficulty understanding is why they have a pattern that has a not ( ^ ) and then if it does not match they create a temporary session id before starting the session. This to me doesn’t make sense – why do they do a pregmatch against not having 0-9a-zA-Z-, ? I just don’t quite understand whats going on here and would like to understand.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:17:02+00:00Added an answer on June 17, 2026 at 8:17 pm

    The caret in the regular expression doesn’t invert the pattern; it’s an anchor to match the beginning of the line.

    Depending on the value configured for session.hash_bits_per_character, the method selects a specific regular expression (zero-or-more matches of either [0-9a-f], [0-9a-v], or [0-9a-zA-Z-,]) as a session identifier recognition pattern.

    If there was no match (!preg_match(...)) for that pattern against the current session identifier (if it didn’t match one of the three patterns) then the session identifier is regenerated; the MD5 hash of the current session identifier becomes the new session identifier and a flag is set to indicate that the regeneration has occurred.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was looking through a code tutorial just now, and found something interesting --
I was looking through someone's code one day and I was annoyed how they
I am looking through code that has multiple naming conventions from multiple developers -
I was looking through some code at work and found something I've not encountered
When looking through some code that was handled by another employee, I see a
I am looking through the source code for a project that relays Windows Event
I was looking through some code the other day and I saw something like
I was looking through some code and found 2 lines that perplexed me: add
I was looking through some code today and saw something like the following: var
Sometime when looking through code, I see many methods specify an annotation: @SuppressWarnings(unchecked) What

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.