php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27394 specific array in session causes data not to store
Submitted: 2004-02-25 10:04 UTC Modified: 2004-02-25 12:33 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: rob_raux at redkeysolutions dot com Assigned:
Status: Not a bug Package: Session related
PHP Version: 4.3.4 OS: Linux 2.4.18-14
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: rob_raux at redkeysolutions dot com
New email:
PHP Version: OS:

 

 [2004-02-25 10:04 UTC] rob_raux at redkeysolutions dot com
Description:
------------
My apologies if this is a dup, I've searched and searched and found nothing.

php.ini [relevant]:
session.save_handler = files
session.save_path = /tmp
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =                                                                                                    
session.serialize_handler = php

As commented in the code, the $_SESSION variable is not correctly set when both $array[1] and $array['string'] are set. 

Reproduce code:
---------------
<?php
                                                                                                    
session_start();
                                                                                                    
//this is our goal, to get here.
if(isset($_SESSION['allSet'])){
  print_r($_SESSION);
  session_destroy();
}
//start the test.
else{
  /* this numeric key creates the problem.
   commented out "$basic_array[0] = 4;" and this code will work fine,
   otherwise we have an infinite redirect. */
  $basic_array[1] = 4;
                                                                                                    
  $basic_array['user_id'] = 4;
  $basic_array['email'] = "rob@rob.com";
                                                                                                    
  foreach(array_keys($basic_array) AS $key){
    $_SESSION[$key] = $basic_array[$key];
  }
                                                                                                    
  $_SESSION['allSet'] = 1;
  header("Location: http://FULLPATHTOSERVER/LOGINTEST.php");
}


Expected result:
----------------
The $_SESSION variable should contain all the relevant data.

Actual result:
--------------
$_SESSION contains no data, despite being set.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-25 12:33 UTC] sniper@php.net
RTFM:

"The keys in the $_SESSION associative array are subject to the same limitations as regular variable names in PHP, i.e. they cannot start with a number and must start with a letter or underscore."

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Dec 03 06:00:02 2025 UTC