/    Sign up×
Community /Pin to ProfileBookmark

SESSION variables disappearing.

Hi all.
I’ve a form that posts to another page. That page turns all the POST variables into SESSION variables (as well as cleans them for MySQL insertion):

[code=php] foreach ($_POST as $k=>$v) {
$v = field_sanitize_basic($v);
$_SESSION[‘form_data’][$k] = $v;
$_SESSION[$k] = $v;
$_POST[$k] = $v;
} [/code]

When I print all the session variables on that receiving page, there they are:

[code=php]foreach($_SESSION as $key=>$value)
{
print $key.” = “.$value.”<br>”;
unset($value);
}[/code]

[code=html]form_data = Array
submit = Submit Changes >>
logged_in = 1
user_role = 102
user_id = 1
user_username = lwatts
last_hit = 2011-06-20 13:36:12
txt_sudiv_geninfo = <p>This is a test of textfield 1.</p>
txt_sudiv_notes = <p>This is a test of textfield 2.</p>
txt_sudiv_events =
txt_sudiv_news =
txt_sudiv_recog =
txt_sudiv_roster = [/code]

But when I go BACK to the previous, form page, when I list the SESSIONS (same print script as above), the SESSION variables for the form don’t show up:

[code=html]form_data = Array
submit = Select SU
logged_in = 1
user_role = 102
user_id = 1
user_username = lwatts
last_hit = 2011-06-20 13:36:12
sel_suinfo = 703[/code]

Why in the world would this be? The SESSION is staying active, obviously by the persistence of the other variables like “user_role,” but just the SESSIONs that are part of the POST just go away.

Any ideas for what I need to look into, I would greatly appreciate it!
Thanks,
Liam

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 20.2011 — ...

But when I go BACK to the previous, form page, when I list the SESSIONS (same print script as above), the SESSION variables for the form don't show up:

...[/QUOTE]


When you say that your "go BACK", are you talking about using the browser's "Back" button? If so, then it's probably not sending a new HTTP request, but just displaying the page from its local cache. If so, for a sanity check, after going back, doing a page refresh should show all the session data in question -- assuming nothing else is wrong.

If that is the case, I'm not sure there is any work-around at the browser level, but you could build a "Back" button into the page that links to the first page, with a warning to the user not to use the browser's "Back" button, if it is an important functional requirement to be able to go back yet have those session values present.

Or, I may be totally misunderstanding the problem. ?
Copy linkTweet thisAlerts:
@Magic_KnightJun 21.2011 — Are you calling session_start() at the top of both pages?

Do both pages have the "www" before the domain? I had a site recently that if you logged in at domain.com, then click a link at www.domain.com, it would ask you to login again, thinking it was a different user / server or whatever.
Copy linkTweet thisAlerts:
@miki1986Jun 21.2011 — hire me at 5$ per hour.

my skype id is baakdaa.
Copy linkTweet thisAlerts:
@mechphistoauthorJun 21.2011 — When you say that your "go BACK", are you talking about using the browser's "Back" button? [...]

Or, I may be totally misunderstanding the problem. ?[/QUOTE]


No, I think you understand the problem. Unfortunately, when I click the back button AND when I'm there and refresh the page, the browser asks me to "resend" the form info. I have no choice, and when I do, still those SESSION keys just aren't there. *sigh*

Maybe a lost cause.

Thanks for the replies!!
Copy linkTweet thisAlerts:
@mechphistoauthorJun 21.2011 — Are you calling session_start() at the top of both pages?

Do both pages have the "www" before the domain? I had a site recently that if you logged in at domain.com, then click a link at www.domain.com, it would ask you to login again, thinking it was a different user / server or whatever.[/QUOTE]


Yeah, session_start() is the first thing on all pages.

As for the form's "action," I'm using relative paths. It's going to "suadmin-proc.php" as opposed to "http://www.domainname.com/pages/suinfo-proc.php".

Think that'll make a difference?
×

Success!

Help @mechphisto spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...