Saving form contents so that they reappear
Moderator: General Moderators
Red,
Each of the pages are 'functions'; this is because the site is driven from a single script, run2.php. I wanted to do this in order to remove the need for so many PHP files.
Therefore, the code really looks like this:
<?php
[core functions such as making the header of the page, footer, standard error output function to be graceful with errors, connecting the MySQL database etc.]
[page functions]
[core code of site, based around the value of 'p' passed through the URL - depending on the value of p, the relevant page function is called. The page functions use the core functions given at the start of the script]
?>
Therefore, I could put session_start() right at the beginning of the script, but I wouldn't be able to destroy it by logging out. I put session_start() only at the beginning of page functions that require it - this is why session_start() is at the start of those page functions.
Each of the pages are 'functions'; this is because the site is driven from a single script, run2.php. I wanted to do this in order to remove the need for so many PHP files.
Therefore, the code really looks like this:
<?php
[core functions such as making the header of the page, footer, standard error output function to be graceful with errors, connecting the MySQL database etc.]
[page functions]
[core code of site, based around the value of 'p' passed through the URL - depending on the value of p, the relevant page function is called. The page functions use the core functions given at the start of the script]
?>
Therefore, I could put session_start() right at the beginning of the script, but I wouldn't be able to destroy it by logging out. I put session_start() only at the beginning of page functions that require it - this is why session_start() is at the start of those page functions.
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
So do you actually need to destroy sessions, or is this carried out automatically anyway?
In which case if I put session_start() right at the beginning of run2.php, would I be able to remove session_start() from the beginning of each of the page functions, and would the session then be automatically destroyed (including session variables etc.) when the user left the site?
In which case if I put session_start() right at the beginning of run2.php, would I be able to remove session_start() from the beginning of each of the page functions, and would the session then be automatically destroyed (including session variables etc.) when the user left the site?
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
Yes if you put it there and take it out elsewhere would be the best course of action at this point. And I don't think moving it there will give you any problems destroying the session. Its a good idea to log out. In playing around, I have not destroyed sessions and closed the window and opened a new one to see that the session vars were definately still filled. (Only if there were other browser windows open that didnt close).
Hi - I've used session_start() at the beginning of the script now, and the site is behaving normally - however this issue with the $_SESSION variables being wiped is still causing problems.
I've been told that normally IE saves the variables so that they are still there when you move 'back' anyway - and yet on mine those INPUT controls are still being wiped!
It has to be something to do with the code, and yet I can't see it. Does anyone have any ideas? It would be really productive for me to get this sorted out.
Thanks
Mark
I've been told that normally IE saves the variables so that they are still there when you move 'back' anyway - and yet on mine those INPUT controls are still being wiped!
It has to be something to do with the code, and yet I can't see it. Does anyone have any ideas? It would be really productive for me to get this sorted out.
Thanks
Mark
The keyword there is 'normally', in my experience it seems to be completely random sometimes it will remember sometime it won't it all seems a bit hit and miss.mjseaden wrote: I've been told that normally IE saves the variables so that they are still there when you move 'back' anyway - and yet on mine those INPUT controls are still being wiped!
It would appear that your code it either not setting the session variables or not recalling them correctly.
Your form input elements at present are generated dynamically dependant on if the session variable isset. If your code is not setting or not recalling the session variables correctly then using isset will always return false. Therefore your code will always apply the form element a value of "" as defined by your code.
You could just removing the isset stuff and you may be lucky in that your browser will decide to remember the values, but I would think it better not to rely on your browser and try to work out why your sessions are not being set or recalled correctly.