severndigital Posted November 9, 2007 Share Posted November 9, 2007 I have two things happening .. when the user logsin .. I am registering sessions automatically with this code $item = array($var1,$var2,$var3,$var4); function registerSessions($item){ foreach($item as $key => $val){ session_register("$key"); $_SESSION["$key"] = $val; } }//END registerSessions this loads sessions that when I echo all the sessions I get duplicates. foreach($_SESSION as $key => $val){ echo "This is session: $key value = $val<BR>"; } returns this: This is session: 0 value = This is session: 0 value = 0 This is session: 1 value = This is session: 1 value = 1 This is session: 2 value = This is session: 2 value = 2 This is session: 3 value = This is session: 3 value = 3 This is session: 4 value = This is session: 4 value = 4 Why is it showing the session twice?? The rest of my code is only pulling the first session .. so if session[0] is empty .. nothing happens. when I navigate to another page and run the same foreach statement. I only get this This is session: 0 value = The session is registered because the number is there session[0]. but it has no value. any ideas?? thanks, chris Link to comment https://forums.phpfreaks.com/topic/76641-solved-session-problems/ Share on other sites More sharing options...
The Little Guy Posted November 9, 2007 Share Posted November 9, 2007 instead of a foreach, do this: print_r($_SESSION); You will need to look at the source code to see the formatted version. Link to comment https://forums.phpfreaks.com/topic/76641-solved-session-problems/#findComment-388050 Share on other sites More sharing options...
severndigital Posted November 9, 2007 Author Share Posted November 9, 2007 it still displays duplicates of the sessions Array ( [0] => [0] => 0 [1] => [1] => 1 [2] => [2] => 2 [3] => [3] => 3 [4] => [4] => 4 ) Link to comment https://forums.phpfreaks.com/topic/76641-solved-session-problems/#findComment-388056 Share on other sites More sharing options...
The Little Guy Posted November 9, 2007 Share Posted November 9, 2007 remove this: session_register("$key"); session_register() is deprecated Link to comment https://forums.phpfreaks.com/topic/76641-solved-session-problems/#findComment-388059 Share on other sites More sharing options...
severndigital Posted November 9, 2007 Author Share Posted November 9, 2007 Ahhh .. yeah .. that solved the duplicate problems.. thank you. Link to comment https://forums.phpfreaks.com/topic/76641-solved-session-problems/#findComment-388060 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.