Re: updating only when data is different On Jul 3, 7:29*am, "C. (http://symcbean.blogspot.com/)"
<colin.mckin...@gmail.com> wrote:
> On Jul 3, 2:43*am, student4life <student4li...@gmail.com> wrote:
>
> > Hello,
>
> > * If I have self-submitting page that will have the data fields
> > refreshed/updated ONLY when the data *are different between each
> > submission, could someone show me what the best way is to accomplish
> > this task? I was thinking using $_SESSION variable and compare the
> > stored value to that of the $_REQUEST variable and proceed with
> > database operations only when there is a difference. TIA
>
> So the form submits itself but between times the user might have
> changed something.
>
> If you use a session then YOU ARE UPDATING THE (session) DATA EVERY
> TIME ANYWAY.
>
> I think the your objective is decidedly dubious, and your proposed
> solution is innappropriate as per above. Assuming that your objective
> is valid, then you could acheive it by including the original values
> in one or more hidden form fields. This does make possible CSRF issues
> would could be avoided by adding additional checks, e.g.
>
> <?php
> $prev=$_REQUEST['prev'];
> unset($_REQUEST['prev'];
> $payload_chk=sha1(var_export($_REQUEST,true) . "s3cr3t"));
> if ($payload!=$prev) {
> * update_date($_REQUEST); // data has changed}
>
> print "<form method='POST'>";
> $payload_chk=sha1(var_export($_REQUEST,true) . "s3cr3t"));
> print "<input type=='hidden' name='prev' value='$old'>";
> ....show rest of form
>
> C.
This current task I do is trivial so I can just do insert/replace to
refresh the data for every request but I was just wondering for
scenario that requires more costly database operations there would
probably be a way to minimize the cost. You indicated that the value
needs to be stored/updated every time in $_SESSION (or temporary
variable) anyway but the way I see is that it's going to be stored/
updated only when it's different from the value in $_REQUEST, no? I
guess what it boils down to is the cost of database operations versus
the cost of persisting objects in the sessions for PHP, in single and
multi-user environments and I was curious to see what the current best
practices are. Maybe someone will see the need for persistent layer
and create one for php too just like Hibernate/TopLink was geared for
Java.
Thanks all for your responses. |