473,508 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ways to assign a value to a session variable.

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?
Jan 14 '08 #1
12 6606
Sorry, I made a mistake. In all 4 cases the second.php should contain
session_start();

Jan 14 '08 #2
unless u r using an older version, otherwise avoid session_register
Jan 14 '08 #3

"Kurda Yon" <ku******@yahoo.comwrote in message
news:42**********************************@f47g2000 hsd.googlegroups.com...
Sorry, I made a mistake. In all 4 cases the second.php should contain
session_start();
Jan 14 '08 #4
that's a given
Jan 14 '08 #5
4 works if you did things right. cannot go more detailed than that unless
see some code.

Jan 14 '08 #6
On Jan 13, 8:43 pm, "Peter Pei" <yan...@telus.comwrote:
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.
Jan 14 '08 #7
On Mon, 14 Jan 2008 02:24:16 +0100, Kurda Yon <ku******@yahoo.comwrote:
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
Jan 14 '08 #8
Kurda Yon wrote:
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.
js*******@attglobal.net
==================

Jan 14 '08 #9
there is a relationship if register_global is on, this is at least true for
5.2.5 on vista

Jan 14 '08 #10
On Jan 13, 8:46 pm, "Peter Pei" <yan...@telus.comwrote:
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.
Jan 14 '08 #11
On Mon, 14 Jan 2008 02:59:39 +0100, Kurda Yon <ku******@yahoo.comwrote:
On Jan 13, 8:46 pm, "Peter Pei" <yan...@telus.comwrote:
>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'];
.........
<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?
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
Jan 14 '08 #12
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?
>
.........
<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?
$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.
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.

Jan 14 '08 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1902
by: Stijn Goris | last post by:
hi all, Having a session variable test . Is there a difference between: $test = "string"; or $_session = "string"; kind regards
2
1419
by: spiderman | last post by:
How can one 'assign' value of a session variable to a variable, something like: temp = session("variable") Thanks
3
4097
by: Jesper Pedersen | last post by:
This works fine: <% Session=1; %> but this: <% Session=%> <%# DataBinder.Eval(Container.DataItem, "playerID") %> <%; %> do not work. The playerID contains the value 1, so the values in both...
1
1402
by: Matt | last post by:
All - Is there a preferred method to assign session variables in ASP.NET / VB.NET? It looks like you can do any of the following to assign values: Session.Item("Foo") = "Bar"...
3
2890
by: Alan Wang | last post by:
Hi there, Once my application gets complicated and complicated. I found it's really hard to keep track of Session value I am using in my asp.net application. I am just wondering if anyone have...
2
3394
by: Mirovk | last post by:
Hi, I have a session variable wich value arrives from a previous .asp but in my actual page I need to modify it based upon a selected value from a radio button. I will try to figure out for...
4
19989
by: philin007 | last post by:
Hi , I have the following javascript codes: ****************************************** <script language="JavaScript"> <!-- .... ..... if (nextRow >5) {
38
2284
by: Zytan | last post by:
What is the difference between these two lines? Dim args As Object() = New Object() {strText} Dim args As Object() = {strText} args seems usuable from either, say, like so: ...
2
7194
by: rahullko05 | last post by:
i am stuck in the problem, where after user logs in successfuly, i take him to the login thanks page. now on that page i need to retain the login name. I am not sure how to this. i have written a...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7118
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5625
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.