Coder Profile - Show off your skills, get a coder profile.
 
 
 
  
Posted: 4.9 Years Ago 

Dice
Australia
Contrib Level: 5
Total Posts: 163
Now i've been thinking over this for a couple of days. As you guys know i needed help with sessions not to long ago. So anyway i've got my script all done but i've run into something else. POSTDATA.

Lets say my script works like this:

// form stuff

// if request[action] is equal to Step 2 get the post data

Now if someone wants to go back or wants to refresh i hate when it comes up saying the POSTDATA message. So i'm thinking is there another way to transfer form data to a new page so that if that person refreshes or goes back it doesn't pop up with that POSTDATA notice.

I read an article that PHP SESSIONS is the way to go if you don't want it appearing. So instead of my current script layout i'd have this:


// form stuff

// if submitted post the form data and create a session for each, then use Header location or meta refresh to go to Step 2

// Step 2 if i refresh or go back the pop-up shouldn't appear.

Now i ask you guys the question is PHP SESSIONS really the best way to handle multiple form data pages?

Or is there another way?

I was actually thinking about storing form data into an XML file and then grabbing data from the file when needed however i'm not sure that is the best option. Or maybe AJAX is a good solution.

Either way i'm looking for some ideas and theories on the best ways to send multiple forms of data across several pages.

Thanks Tom
Posted: 4.9 Years Ago 

VBAssassin
United Kingdom
Contrib Level: 17
Total Posts: 5,730
QUOTE:  Remove Scroll Bars
Now if someone wants to go back or wants to refresh i hate when it comes up saying the POSTDATA message. So i'm thinking is there another way to transfer form data to a new page so that if that person refreshes or goes back it doesn't pop up with that POSTDATA notice.
I read up to their and stopped. Yes there is.

Just do a redirect after the POST data has been sent and pass a GET variable to show a confirmation message.
CODE: Copy / Restore  ::  Remove Scroll Bars
  1. header("Location: {$_SERVER['PHP_SELF']}?conf=yes");
Kind regards,
Scott
Posted: 4.9 Years Ago 

Seachmall
Ireland
Contrib Level: 9
Total Posts: 965
Post Quote - Direct Reference
Thanks for that, I normally have the same problem with POST and never thought of redirecting to the same page, seems pretty obvious when you think of it
Posted: 4.9 Years Ago 

VBAssassin
United Kingdom
Contrib Level: 17
Total Posts: 5,730
Your welcome.

The other way is to show a page after the post and use that page to redirect after X seconds. it's how IPB and other forums do it... but i don't like that method

Kind regards,
Scott
Posted: 4.9 Years Ago 

Dice
Australia
Contrib Level: 5
Total Posts: 163
Post Quote - Direct Reference
That's exactly how i did it.

Also is there a maximum amount of Sessions you can have?

Also for an individual session. Is there a character limit?
Posted: 4.9 Years Ago 

VBAssassin
United Kingdom
Contrib Level: 17
Total Posts: 5,730
No there is not a maximum amount of sessions. The maximum character limit is what ever the maximum length of a filename on your OS. Since each session is actually the name of a file on your system.

Kind regards,
Scott
Posted: 4.9 Years Ago 

Dice
Australia
Contrib Level: 5
Total Posts: 163
Bingo!

Thanks for that. Exactly what i needed. (Had problems displaying quite a large session and it might be because of that. :P

Thanks. :)
Posted: 4.9 Years Ago 

xLink
United Kingdom
Contrib Level: 5
Total Posts: 164
if you have a problem with enough 'room' in sessions then ive heard serialize() is a good function to use..not actually used it or know what it does so maybe VBAassassin can give a little insite there :)
Posted: 4.9 Years Ago 

VBAssassin
United Kingdom
Contrib Level: 17
Total Posts: 5,730
Post Quote - Direct Reference
Na you don't need serialize for that. Serialize converts pretty much anything in PHP that has already been constructucted such as an object or array.... and converts it to text form which can then be stored in a file for example without losing any structure or information. Then it can be unserialized and restored at a later date.

Kind regards,
Scott
Posted: 4.9 Years Ago 

Dice
Australia
Contrib Level: 5
Total Posts: 163
Post Quote - Direct Reference
Wow cool!

So basically i can use this serialize function to save stuff into a file. And then later on in my script i can call it up again. That's cool.

*Starting to think i should have used more of that*

Just a thought, so this is similar to the fwrite and fopen functions when fopen is in write mode?

Which would you prefer for lets saying having to store some data and then3 pages ahead you need that data again. The bad thing is that the data is too large to be carried in a Session and POST won't work.

How would you approach it, Serialize or file reading?
Posted: 4.9 Years Ago 

VBAssassin
United Kingdom
Contrib Level: 17
Total Posts: 5,730
Wew... nooo... you'd be better using file based caching for that. I wrote a script in PHP that can cache pages (its on my profile).

Anyway the serialize function on stores what could otherwise be stored in a variable eg:
CODE: Copy / Restore  ::  Remove Scroll Bars
  1. //serialize and store the array in a file
  2. $names = array('scott','adam','matt');
  3. file_put_contents('file', serialize($names));
  4. unset($names);
  5.  
  6. //restore the array
  7. $names = unserialize(file_get_contents('file'));
It would be done like that. Thats pseudo code since i haven't checked it or anything :-p but it shows how it could be used.

You should not be storing whole pages in a session anyway! They should only store variables and alike.

Kind regards,
Scott
Page of 2 :: Next Page >>
 
 
Latest News About Coder Profile
Coder Profile Poll
Why do you get bored with programming?

Not enough time to do something productive
I run out of ideas
Too hard to show people my creations
Everything i do has too many errors, and it's too hard
I don't get bored!!!


please login to cast your vote
and see the results of this poll
Latest Coder Profile Changes
Coder Profile was last updated
3.49 Years Ago
Official Blog :: Make A Donation :: Credits :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents :: Wallpapers
Version 1.46.00
Copyright © 2007 - 2012, Scott Thompson, All Rights Reserved