PDA

View Full Version : PHP question, can't interpret manuals



leaded
5th December 2004, 05:59 AM
I'm programming some forms on a RH 7 server (not mine) with PHP 4.3.8.

I have some easy questions about session variables and post variables, and the documentation I found doesn't really help answer them.

I was hoping someone friendly couple help me out here. I don't really want to register at another forum if I don't have to!

Ok, so the call for session_start();... when does this need to be done? Every page that uses a session variable?

Also, if I'm using the $_POST array, it doesn't look like I need to use session_start();... is this true?

If I have two pages of forms, it seems like I lose the $_POST info after I submit the second form... if both forms have the same name="form1" will my $_POST entries from the first form carry through past the second, and include the second?

Maybe I should buy a book... lol...

Id4qiBd2
5th December 2004, 09:20 AM
If you're coding multiple forms on multiple pages, and want to maintain what the responses were from page 1 after page 2 is submitted, you're going to have to write the responses from page 1 to some type of datastore, be it a session variable of some type, a database, flat files, what have you.

session_start() would need to be called at the beginning of each page that utilizes session variable information, yes.

If you're using the $_POST array when a page is submitted, no you don't necessarily need to involve session information, unless you're hoping for the information coming in via that $_POST array to be maintained between multiple page requests.... you're going to need to copy that information into some data store.... most likely the session in this case.

As for the last question.... your $_POST information won't carry over from page 1 to page 3, even if your forms have different names. It's not like form submissions of the same name over write each other in the $_POST array. The $_POST array starts empty with each request (that's what HTTP being "stateless" is all about, nothing persists) and is then only populated if something is being POST'ed as part of that request. To maintain that information, you need to take action to store it somewhere.

Hope that makes sense and helps.....

Jman
6th December 2004, 09:06 AM
Moved to Programming.