Hi all,
I was curious if one can put an array in a session variable.
I want to store some search results in such a variable,
so it would be an array of objects. However I don't know
if that was even the intended purpose of a session variable,
and I also don't know how long session variables are held,
or if there is a maximum size for a session variable.
Can anyone explain?
Thanks for any info... 18 4899 pl*******@yahoo.com wrote:
Hi all,
I was curious if one can put an array in a session variable.
I want to store some search results in such a variable,
so it would be an array of objects. However I don't know
if that was even the intended purpose of a session variable,
and I also don't know how long session variables are held,
or if there is a maximum size for a session variable.
Can anyone explain?
Thanks for any info...
Of course it's possible, sessions are stored server-side and there's
basically no limitation.
<?php $_SESSION[] = $my_array; ?>
It's just a bidimensional array.
-thib´
PS you can define a key for the array in the $_SESSION as well. pl*******@yahoo.com wrote:
Hi all,
I was curious if one can put an array in a session variable.
I want to store some search results in such a variable,
so it would be an array of objects. However I don't know
if that was even the intended purpose of a session variable,
and I also don't know how long session variables are held,
or if there is a maximum size for a session variable.
Can anyone explain?
Thanks for any info...
The manual can explain!
Try typing
php session objects
into Google and clicking the "I'm Feeling Lucky" button
1)your sample won't work, at least not with php's current shape.
2) Of course it's <possible>, is it possible, or a definite yes. be precise
Peter Pei wrote:
1)your sample won't work, at least not with php's current shape.
2) Of course it's <possible>, is it possible, or a definite yes. be precise
1) Ah?
<?php
session_start();
$_SESSION[] = array('why', 'wouldn\'t', 'this', 'work?');
echo '<pre>' . print_r($_SESSION, true) . '</pre>';
?>
outputs:
Array
(
[0] =Array
(
[0] =why
[1] =wouldn't
[2] =this
[3] =work?
)
)
Well, I must admit, I got a notice here:
Notice: Unknown: Skipping numeric key 0. in Unknown on line 0
By defining a non-numeric key for the array, it doesn't display this notice,
so I guess $_SESSION have special rules (I'm not that familiar with it)
until a 'normal' array will accept this code very well (I don't see any
glitch in $_SESSION neither).
2) I'm sorry, I must have missed something. I'm aware my English is not
perfect at all, maybe the literal translation hasn't the same meaning in
French and in English, or whatever; I'm frustrated I don't get what you
mean. Anyway, what I meant is "Definitely yes, it's possible to use arrays
in sessions".
-thib´
on point 1, you are getting closer
Peter Pei wrote:
on point 1, you are getting closer
Hum.. I did explain exactly what the OP was asking. If you want plain
example of what I just said, here it is:
<?php
session_start();
$_SESSION['some_array'] = array('why', 'wouldn\'t', 'this', 'work?');
echo '<pre>' . print_r($_SESSION, true) . '</pre>';
?>
-----
Array
(
[some_array] =Array
(
[0] =why
[1] =wouldn't
[2] =this
[3] =work?
)
)
String key, thus no notice. Is something wrong with that?
*scratches his head*
-thib´
string key is fine, I meant u were closer on the number key thing
Peter Pei wrote:
string key is fine, I meant u were closer on the number key thing
O-kay
Did some little search then, and found the logical reason: hellish globals
strike again. Even if register_global is off, PHP throws this notice simply
because of variables naming limitations (in this case it cannot start with
numbers).
As far as we don't register globals, I think we can simply @ignore this
notice and sleep well (correct me if there's something else).
Not talking about portability, of course.
Thanks for making me discovering it out ;).
-thib´
right on! you got the reason. but unfortunately it won't work regardless. to
me, this is a bug in the language. if register_global turned off, numbers
should be allowed, however in reality php simply skips the assignment, and
this mess up yr subsequent pages - session_start won't be able to bring back
the indexed array element, although it appears to be fine on the same page
thib´ wrote:
Peter Pei wrote:
>string key is fine, I meant u were closer on the number key thing
O-kay
Did some little search then, and found the logical reason: hellish
globals strike again. Even if register_global is off, PHP throws this
notice simply because of variables naming limitations (in this case it
cannot start with numbers).
Yep, it's a minor annoyance, but I can understand it. Maybe this
restriction will be removed some day when they completely get rid of
register_globals :-)
As far as we don't register globals, I think we can simply @ignore this
notice and sleep well (correct me if there's something else).
Probably could, but I personally don't like it. But then I always have
a name for anything I put in the $_SESSION variable anyway, so I can get
it back easily.
Not talking about portability, of course.
Thanks for making me discovering it out ;).
-thib´
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
his suggestion won't work. I see this as a bug.
Thanks for any info...
Yes, it is serialized automatically. Which directly leads to the question:
Can I store objects in sessions?
Yes, you can, but you have to be sure, that the class definition is
included/includeable by autoload ON EVERY PAGE THE SESSION IS LOADED.
Yes, loaded. Not every page, the object is used but on every page the
session is loaded, because in other cases, the object will break when
unserialising.
..oO(thib´)
>Peter Pei wrote:
>string key is fine, I meant u were closer on the number key thing
O-kay Did some little search then, and found the logical reason: hellish globals strike again. Even if register_global is off, PHP throws this notice simply because of variables naming limitations (in this case it cannot start with numbers).
Correct.
>As far as we don't register globals, I think we can simply @ignore this notice and sleep well (correct me if there's something else).
The notice "Skipping numeric key 0 ..." also means that these variables
are _not_ stored in the session file, hence you cannot ignore it.
Currently $_SESSION acts as an associative array only, so no numeric
keys are allowed.
Micha
..oO(Peter Pei)
>of course, why not,
Why what? Your quoting sucks!
Micha
Michael Fesser wrote:
The notice "Skipping numeric key 0 ..." also means that these variables
are _not_ stored in the session file, hence you cannot ignore it.
Currently $_SESSION acts as an associative array only, so no numeric
keys are allowed.
Micha
Thanks for the correction, that's definitely good to know.
-thib´
On Jan 14, 4:08 am, Jonas Werres <jo...@example.orgwrote:
Thanks for any info...
Yes, it is serialized automatically. Which directly leads to the question:
Can I store objects in sessions?
Yes, you can, but you have to be sure, that the class definition is
included/includeable by autoload ON EVERY PAGE THE SESSION IS LOADED.
Yes, loaded. Not every page, the object is used but on every page the
session is loaded, because in other cases, the object will break when
unserialising.
Not to digress too much, but if storing objects in the session, it is
useful to be familiar with the magic sleep and wakeup methods. I've
made this mistake a few times - and caused a few issues with other
resources stored as references inside of the objects. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Al Jones |
last post by:
This is a repost form the vbscript newgroup - if this isn't the appropriate
group would you point me toward one that is.
Basically, I seem to be losing session data part way though preparing an...
|
by: Lina Manjarres |
last post by:
Hello,
I have a session variable in a login page. Then I go to a form page where I
uses the ProfileID and the UserID. Then I go to a result page where I would
like to use the UserID as a filter,...
|
by: PJ |
last post by:
A particular page seems to be having issues with correctly setting Session
variables. I am setting a couple of session variables on the Page_Unload
event. While stepping through code, the...
|
by: Harry Simpson |
last post by:
I've come from the old ASP camp where session variables were not used. When
i started using ASP.NET in 2001, I started using them again because it was
ok from what I'd read.
I've been merrily...
|
by: tshad |
last post by:
I have been using the default session state (InProc) and have found that I
have been loosing my information after a period of time (normally 20
minutes).
Is there anyway to find out how much...
|
by: Alan Wang |
last post by:
Hi there,
Once my application gets complicated and complicated. I found it's really
hard to keep track of Session value I am using in my asp.net application. I
am just wondering if anyone have...
|
by: Phillip N Rounds |
last post by:
I'm writing a user control which has two states: Active & InActive. I
additionally am required that there to be only one active control per page,
and all logic has to be contained within the...
|
by: BillE |
last post by:
When a user opens a new IE browser window using File-New-Window the
integrity of an application which relies on session state is COMPLETELY
undermined. Anyone who overlooks the fact that...
|
by: BillE |
last post by:
Some ASP.NET applications use Session Variables extensively to maintain
state.
These should be re-written to use viewstate, hidden fields, querystring,
etc. instead.
This is because if a user...
|
by: MrHelpMe |
last post by:
Hello again all,
I've finished my whole application and now I don't like the whole
session variables that I am using. I have a form, user fills in info
clicks submit and using CDOSYSMail an...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |