How is the information stored in a session, is it like an array? If I want to remove one element from the seeesion would I use code like this
unset($variable_name[$position]);
I tried something like this already and it seemed to remove everything from the session. Any help would be great thanks.
Stephen
Well to learn about sessions read this: http://www.php.net/manual/en/ref.session.php
To learn how to remove a variable from a session read this: http://www.php.net/manual/en/function.session-unregister.php
As to your question. Sessions are stored as serialized strings in a text file on the hard drive of the server. The file is named something unique that matches the session id so that it can be retrieved and unserilized. for your use in the program.
If you want to remove a variable from your session you have the "session_unregister('varName')" function.
I tried that and it does not seem to work. I know what position the item I want to delete is in but still it does not work.
Say I have a session called carte and would like to delete the second item out of it.
Would this code work session_unregister('$carte[1]')
Let me know please
Try session_unregister('varname') ...without '$' and then unset($varname)
I hope this would help
No that probably wouldn't work since as Francisco pointed out you need to use the name of the session variable not the actual variable. Plus I doubt that the session handling function cares what type of variable you are storing so it probably doesn't know how to handle arrays.
I'd suggest that you retrieve your $cart variable then unset($cart[1]) or something similar then re-register it. That should force the change.
Try something like this ...
session_start(); $var1=array(a=>array(1,2,3),b=>array(4,5,6)); session_register('var1');
session_unregister('var1'); unset($var1['b']); Cheers!