Connecting Tech Pros Worldwide Forums | Help | Site Map

Ways to assign a value to a session variable.

Kurda Yon
Guest
 
Posts: n/a
#1: Jan 14 '08
I am wandering which way to assign a value to a session variable
exist. Which of the following examples will work.

Example #1:
session_start();
session_register("ex");
$ex = 2.0;

Example #2:
In first.php:
session_start();
session_register("ex");
In second.php:
$ex = 2.0;

Example #3:
In first.php:
session_start();
session_register("ex");
Load second.php?ex=2.0

Example #4:
In first.php:
session_start();
session_register("ex");
Go to the second.php via submission of the form on the first.php,
which contains form-variable $ex.

Example #4 seams not to work? Is it expectable?

Kurda Yon
Guest
 
Posts: n/a
#2: Jan 14 '08

re: Ways to assign a value to a session variable.


Sorry, I made a mistake. In all 4 cases the second.php should contain
session_start();

Peter Pei
Guest
 
Posts: n/a
#3: Jan 14 '08

re: Ways to assign a value to a session variable.


unless u r using an older version, otherwise avoid session_register
Peter Pei
Guest
 
Posts: n/a
#4: Jan 14 '08

re: Ways to assign a value to a session variable.



"Kurda Yon" <kurdayon@yahoo.comwrote in message
news:420f8581-3870-4908-bb70-61593fbcac8b@f47g2000hsd.googlegroups.com...
Quote:
Sorry, I made a mistake. In all 4 cases the second.php should contain
session_start();
>
Peter Pei
Guest
 
Posts: n/a
#5: Jan 14 '08

re: Ways to assign a value to a session variable.


that's a given
Peter Pei
Guest
 
Posts: n/a
#6: Jan 14 '08

re: Ways to assign a value to a session variable.


4 works if you did things right. cannot go more detailed than that unless
see some code.

Kurda Yon
Guest
 
Posts: n/a
#7: Jan 14 '08

re: Ways to assign a value to a session variable.


On Jan 13, 8:43 pm, "Peter Pei" <yan...@telus.comwrote:
Quote:
unless u r using an older version, otherwise avoid session_register
The example #4 seems not to work. In the second file the session
variable do not want to take the value of the form variable. I tried
to force session to do it by the explicit command: $_SESSION["ex"] =
$ex; But it also does not help. I think that session value of the
variable has a higher priority with respect to the from variable. In
the first file I set the value to the session variable $ex, and than I
submit a form which change the value of the $ex variable, but the
second file does not want to see the values of the form variables. It
sees the values of the session variables.
Rik Wasmus
Guest
 
Posts: n/a
#8: Jan 14 '08

re: Ways to assign a value to a session variable.


On Mon, 14 Jan 2008 02:24:16 +0100, Kurda Yon <kurdayon@yahoo.comwrote:
Quote:
I am wandering which way to assign a value to a session variable
exist. Which of the following examples will work.
Don't use session_register() anymore. Use a reference if you must.
--
Rik Wasmus
Jerry Stuckle
Guest
 
Posts: n/a
#9: Jan 14 '08

re: Ways to assign a value to a session variable.


Kurda Yon wrote:
Quote:
I am wandering which way to assign a value to a session variable
exist. Which of the following examples will work.
>
Example #1:
session_start();
session_register("ex");
$ex = 2.0;
>
Example #2:
In first.php:
session_start();
session_register("ex");
In second.php:
$ex = 2.0;
>
Example #3:
In first.php:
session_start();
session_register("ex");
Load second.php?ex=2.0
>
Example #4:
In first.php:
session_start();
session_register("ex");
Go to the second.php via submission of the form on the first.php,
which contains form-variable $ex.
>
Example #4 seams not to work? Is it expectable?
>
session_register() has been deprecated. The correct way to do it is to
use the $_SESSION superglobal array, i.e.

session_start();
$_SESSION['ex'] = 2.0;

session_start();
$ex = $_SESSION['ex'];

BTW - there is no direct relationship between 'ex' as an index value,
and $ex as a variable.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Peter Pei
Guest
 
Posts: n/a
#10: Jan 14 '08

re: Ways to assign a value to a session variable.


there is a relationship if register_global is on, this is at least true for
5.2.5 on vista

Kurda Yon
Guest
 
Posts: n/a
#11: Jan 14 '08

re: Ways to assign a value to a session variable.


On Jan 13, 8:46 pm, "Peter Pei" <yan...@telus.comwrote:
Quote:
4 works if you did things right. cannot go more detailed than that unless
see some code.
OK. In the first.php I have:
session_start();
session_register("ex");
$ex = 2.0;
..........
<form enctype="multipart/form-data" action="second.php" method="post">
......
print "<input type='text' name='ex' value=\"$ex\">\n";
......
</form>

When I submit the form I put in the text field corresponding to $ex
3.0.

In the second.php I have:
session_start();
$_SESSION["ex"] = $ex;
print "===$txt_l_1";
print "---{$_SESSION["txt_l_1"]}";
die();

As the output I have:
===2.0
---2.0

Not 3.0, as I expect.
Rik Wasmus
Guest
 
Posts: n/a
#12: Jan 14 '08

re: Ways to assign a value to a session variable.


On Mon, 14 Jan 2008 02:59:39 +0100, Kurda Yon <kurdayon@yahoo.comwrote:
Quote:
On Jan 13, 8:46 pm, "Peter Pei" <yan...@telus.comwrote:
Quote:
>4 works if you did things right. cannot go more detailed than that
>unless
>see some code.
>
OK. In the first.php I have:
session_start();
session_register("ex");
$_SESSION['ex'] = 2.0;
$ex = &$_SESSION['ex'];
Quote:
.........
<form enctype="multipart/form-data" action="second.php" method="post">
.....
print "<input type='text' name='ex' value=\"$ex\">\n";
.....
</form>
>
When I submit the form I put in the text field corresponding to $ex
3.0.
>
In the second.php I have:
session_start();
$_SESSION["ex"] = $ex;
Why overwrite the value in the $_SESSION array here? If you're not even
using it, why store it to begin with?
Quote:
print "===$txt_l_1";
print "---{$_SESSION["txt_l_1"]}";

Euhm, what magic do you expect from a in this sample code uninitiated &
unassigned variable $txt_1_1?
--
Rik Wasmus
Kurda Yon
Guest
 
Posts: n/a
#13: Jan 14 '08

re: Ways to assign a value to a session variable.


Quote:
Quote:
OK. In the first.php I have:
session_start();
session_register("ex");
>
$_SESSION['ex'] = 2.0;
$ex = &$_SESSION['ex'];
What for do you introduce $ex variable? What for do you have "&" in
the second line?
Quote:
>
Quote:
.........
<form enctype="multipart/form-data" action="second.php" method="post">
.....
print "<input type='text' name='ex' value=\"$ex\">\n";
.....
</form>
>
Quote:
When I submit the form I put in the text field corresponding to $ex
3.0.
>
Quote:
In the second.php I have:
session_start();
$_SESSION["ex"] = $ex;
>
Why overwrite the value in the $_SESSION array here? If you're not even
using it, why store it to begin with?
>
$ex supposed to be a form variable and before to use "header" I would
like to put the values of the form variables into the session
variables.
Quote:
Quote:
print "===$txt_l_1";
print "---{$_SESSION["txt_l_1"]}";
>
Euhm, what magic do you expect from a in this sample code uninitiated &
unassigned variable $txt_1_1?
Instead of $txt_l_1 should be $ex.

Closed Thread