Re: object in $_SESSION [message #174401 is a reply to message #174399] |
Fri, 10 June 2011 09:20 |
Erwin Moller
Messages: 228 Registered: September 2010
Karma:
|
Senior Member |
|
|
On 6/10/2011 10:02 AM, Jivanmukta wrote:
> Hello,
> I need your opinions about my solution of some programming probem. I
> have little experience in web developement and PHP.
> I have a page insert_send.html with a form. The user enters into the
> form path of HTML file with bank statement and presses submit button.
> Then import_statement.php program is executed. The program imports
> bank statement into Statement object (which is complicated task) and
> runs:
> $_SESSION['statement'] = serialize($statement);
> headerLocation('send_emails.php');
> Then send-emails.php program is executed. It runs:
> $statement = unserialize($_SESSION['statement'];
> and sends emails according to statement positions (which is
> complicated task, too).
> My question: is the method of transferring Statement object through
> session array acceptable in my case? One man told me that passing
> objects through sessions is usually an error, but I don't know why.
Hi,
You must make sure that your object:
1) is defined (it's class is defined) BEFORE starting the session (via
session_start() that is. Do not use autostart in such scenarios)
2) You object cannot contain references to file-handles,
databaseconnections, etc. Only "plain" date that can be serialized.
So it can be done, but I never found myself in a situation where I
needed it.
So I tend to agree with the abovementioned "One man": Don't, unless you
must for some reason.
Regards,
Erwin Moller
> I decided to separate importing of bank statement and sending emails
> into two different files becase of complexity of these tasks.
> Please help. Thanks in advance.
>
> newbie
--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens
|
|
|