Page 3 of 3
Posted: Wed Mar 24, 2004 11:23 am
by redmonkey
The first thing I'd be tempted to do is to remove the session_start() from within the function and place that as the first line of code in your page.
Posted: Wed Mar 24, 2004 11:34 am
by mjseaden
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.
Posted: Wed Mar 24, 2004 11:38 am
by magicrobotmonkey
I think you can still destroy it - you start it and destroy it on the same page anyways, and then if its still there, who cares, it was destroyed its now a new blank session
Posted: Wed Mar 24, 2004 11:39 am
by mjseaden
So is it the session_start() that is causing the problem?
Posted: Wed Mar 24, 2004 11:41 am
by mjseaden
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?
Posted: Wed Mar 24, 2004 11:45 am
by magicrobotmonkey
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).
Posted: Wed Mar 24, 2004 1:41 pm
by mjseaden
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
Posted: Wed Mar 24, 2004 2:47 pm
by redmonkey
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!
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.
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.
Posted: Wed Mar 24, 2004 2:58 pm
by mjseaden
redmonkey, you're a star! You are the greatest! After me spending all this time on it, all of my mates who program for a living couldn't work it out - you're brilliant! Superb, nice job!
FAO moderator, it's solved (finally).