By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,124 Members | 1,528 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,124 IT Pros & Developers. It's quick & easy.

Question about session variables and visiting various pages.

P: n/a
I am working on a site that will have several pages and where the user will
find some investment advices. I must say that the concept of
sessions/session variables is relatively new for me.
What I noticed is the following: when I write "form method is ""post"
action = page2.php", and in page2.php I write
"session_register("someVariable") the value of the variable is registered
but if I visit some further pages and go back to page1, I cannot change the
value of the variable anymore by changing the content of the form field. The
only thing I can figure out to resolve this problem would using the
HTTP_REFERER : if the user comes from page 2 the variable should be
unregistered in page 1, so it can be registered in page 2 again.
I have been looking in Google for better alternatives for such a multiple
page site but maybe I just entered the wrong searching keywords.
Any suggestion or even a link to a page that discusses this topic will be
very welcome.
Thanks,
Martien van Wanrooij

Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
The interactive between GET, POST, and session variables is rather confusing
when register_globals is turned on. Basically, a GET or a POST cannot
overwrite a session variable. After you registered a variable its value can
only be changed programmatically.

Avoid using session_register(). Instead, access session variables through
$_SESSION[]. Say you want a variable that changes when a POST occurs, but
stays put as you go from page to page, you would do something like:

if(isset($someVariable)) {
$_SESSION['someVariable] = $someVariable;
}
else {
$someVariable = $_SESSION['someVariable'];
}

Uzytkownik "Martien van Wanrooij" <in**@martienvanwanrooij.nl> napisal w
wiadomosci news:KKzMb.822$tK2.1810@amstwist00...
I am working on a site that will have several pages and where the user will find some investment advices. I must say that the concept of
sessions/session variables is relatively new for me.
What I noticed is the following: when I write "form method is ""post"
action = page2.php", and in page2.php I write
"session_register("someVariable") the value of the variable is registered
but if I visit some further pages and go back to page1, I cannot change the value of the variable anymore by changing the content of the form field. The only thing I can figure out to resolve this problem would using the
HTTP_REFERER : if the user comes from page 2 the variable should be
unregistered in page 1, so it can be registered in page 2 again.
I have been looking in Google for better alternatives for such a multiple
page site but maybe I just entered the wrong searching keywords.
Any suggestion or even a link to a page that discusses this topic will be
very welcome.
Thanks,
Martien van Wanrooij

Jul 17 '05 #2

P: n/a

"Chung Leong" <ch***********@hotmail.com> schreef in bericht
news:5a********************@comcast.com...
Avoid using session_register(). Instead, access session variables through
$_SESSION[]. Say you want a variable that changes when a POST occurs, but
stays put as you go from page to page, you would do something like:

if(isset($someVariable)) {
$_SESSION['someVariable] = $someVariable;
}
else {
$someVariable = $_SESSION['someVariable'];
}

Thank you Chung, I think this will resolve my problem :)
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.