Coderguy’s Blog

Thoughts on code

About

Hello, my name is Daniel Ice. I am a software developer in the Dallas, TX area. I enjoy learning about new technology. I mostly focus on PHP and Ruby on Rails.

I was working on a 404 page today.  The pages that detected the 404 and routed it to the 404 page, would try and set the $_SESSION['404'] variable.  After setting the variable I was able to use it on that page.  However, after the redirect the variable was missing.  I could set other variables, and they would remain from page to page.  I put in some extra debugging and received the message:

Notice: Unknown: Skipping numeric key 404

This lead me to rename my variable to $_SESSION['url404'], which would stay set on the redirect.  I have not found any documentation that says that numeric keys are illegal for sessions vars, but I believe it to be the case.

Hope this saves you time in your PHP coding.

3 Responses to “PHP Session Numeric Key Bug”

  1. I’ve found this tooo.. but the solution for this could be not using session variables having integer as starting.
    It is valid also. For declaring a variable it should have _, a-z, A-Z as the start and later they may contain integers but not special characters..

    Siddhesh

  2. Yeah I had the same problem too, with my own 404 file. Renamed it to ['fourofour'] and the problem went away!

    sunnyfrimley

  3. Just got bit by this too.

    However, just to note, this is only true for the first level of the array.

    ['errorPages']['404'] will work fine.

    Celly

Leave a Reply