Re: [houston-php] session_start() issues

From: Clint V.
Sent on: Monday, August 30, 2010 5:25 PM
Brandon's message pretty much hit this right on. The link you provided seems to be doing what it should do when you hit back. I think you might be confusing the back behavior with the refresh behavior or have already fixed it. session_start() just loads up $_SESSION (from a cookie - PHP_SESSID) and sets that cookie for the user to return on the next request. session_start does not destroy anything. All browsers I know of will persist that cookie (once its set) even if you go through a couple pages without session_start().

The way you are going about your form submission can work fine for some people, however the thing I have learned in the past is that if you reinvent the wheel, expect some growing pains. That's just the warning I feel obligated to make when I see stuff like this?<input type="hidden" name="allcontrol" value="5;10;15;20"> to cope with?<input type="hidden" name="lbl10" value="Model:"> and this?<input type="text" name="dyn10" value="">. I think when you go to actually put any kind of difficult business case into play here, your going to end up with a lot more workload just to get the same results. ?This type of infrastructure might make things harder instead of simpler. If you must go down this road, then here is a trick that might help. (sorry if there are any bugs I just typed this out off the top of my head)

You can build a object or array of data in php:
$fields = array(
?? ?'10' => array(
?? ? ? ?'label' => 'Model',
?? ? ? ?'required' => true
?? ?)
);

then json_encode it (inside your form tag):
<span style="display: none" id="fieldData"><?= filter_var(json_encode($fields), FILTER_SANITIZE_SPECIAL_CHARS) ?></span>

and manipulate that in javascript (using jQuery here):
var fieldData = JSON.parse( $('#fieldData').html() );
for (var field in fieldData) {
?? ?alert (field.label);
}

This will allow you to send more complicated validation information without needing a bunch of extra inputs when you start getting into some real world cases. Instead of rolling your own though, I would recommend that you use a library that is already built to do this for you. ?Take a look at?http://www.massimocorner.com/libraries/validator/?it looks like it might do for you. Also remember, even if you add the client side validation you still must do server-side validation for security reasons.

I am not sure this is the best piece to illustrate what I am saying about just sticking to the basics, but consider the content.

As a final word of advice, I have seen many and even currently help maintain one program that does submits/redirects for every little thing you do with it's form. They are massively irritating to the user (I hear it on a daily basis). Try to make use of AJAX where possible if you need this behavior, and your user's will greatly appreciate it.

On Wed, Aug 25, 2010 at 8:35 PM, Jonny Nguyen <[address removed]> wrote:
session_start() is the first thing in my application. That what puzzle me. It also happen over and over again.


On Wed, Aug 25, 2010 at 7:12 PM, Eddie <[address removed]> wrote:
Session_start() creates a new session, which will naturally erase any form values. You should start your session first, then save the values in your form.

Edward F. Prislac
Multimedia Specialist
Infodat International, Inc. | 9990 Richmond Ave, Suite 250N | Houston, TX 77042
Phone:[masked] x14 | Mobile:[masked] | Fax:[masked]
www.infodatinc.com


From: Jonny Nguyen <[address removed]>
Sender: [address removed]
Date: Wed, 25 Aug[masked]:29:09 -0400
To: <[address removed]>
ReplyTo: [address removed]
Subject: [houston-php] session_start() issues

I experience a strange behavior with session_start().

My browser back button is not working correctly when i use the session_start(); It loads the previous page but non of the form values gets loaded. it comes up as a new request.
I have a form validation that will use the parent.history.back() if it fails. this validation works fine when i don't use the session_start().? when I do use the session_start() it will just reset all the values in the form. I have tested this in IE and in Firefox and get the same behaviors.

I have look far and near and have not been able to find anything useful.

please let me know you have encounter this issue in the past.

thanks in advance

Jonny




--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Jonny Nguyen ([address removed]) from Houston PHP Users Group.
To learn more about Jonny Nguyen, visit his/her member profile
To unsubscribe or to update your mailing list settings, click here

Meetup, PO Box 4668 #37895 New York, New York[masked] | [address removed]



--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Eddie ([address removed]) from Houston PHP Users Group.
To learn more about Eddie, visit his/her member profile

To unsubscribe or to update your mailing list settings, click here

Meetup, PO Box 4668 #37895 New York, New York[masked] | [address removed]





--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Jonny Nguyen ([address removed]) from Houston PHP Users Group.
To learn more about Jonny Nguyen, visit his/her member profile
To unsubscribe or to update your mailing list settings, click here

Meetup, PO Box 4668 #37895 New York, New York[masked] | [address removed]

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy