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

$_SESSION vs. $variable

P: n/a
Ken
What am I doing wrong?

I set the variable co_name on the first page with an <input.... > and
session_start() at the top of both pages.

Clicking on a link that takes me to the second page:

Script on the second page.

echo $_SESSION['co_name']; Does not display
value of co_name
echo "Variable name co_name = ".$co_name; Displays value of co_name

One book suggested using echo {$_SESSION['co_name']}; Does not run.

Server is Apache2 Triad

Any suggestions. I would like to use $_SESSION incase I move to another
server without ??register_globals?? ON

Thanks for the help.
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Ken wrote:
What am I doing wrong?

I set the variable co_name on the first page with an <input.... > and
session_start() at the top of both pages.

Clicking on a link that takes me to the second page:

Script on the second page.

echo $_SESSION['co_name']; Does not display
value of co_name
echo "Variable name co_name = ".$co_name; Displays value of co_name

One book suggested using echo {$_SESSION['co_name']}; Does not run.

Server is Apache2 Triad

Any suggestions. I would like to use $_SESSION incase I move to another
server without ??register_globals?? ON

Thanks for the help.


You have considered the manual at php.net ?
Especially about session_register("co_name") prior to $_SESSION["co_name"] =
"something" on the first page ?

Or rather, in your case a minor rewrite according to the input statement ?

/Andreas
--
Peace and long life ...
Registeret Linux user #292411
Jul 17 '05 #2

P: n/a
Ken wrote:
What am I doing wrong?

I set the variable co_name on the first page with an <input.... > and
session_start() at the top of both pages.
How are you putting co_name into the session variable on the first page?
Clicking on a link that takes me to the second page:

Script on the second page.

echo $_SESSION['co_name'];


The PHP manual for session_register()
( @ http://www.php.net/session_register )
has a word of caution against using session_register() and $_SESSION
together.
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #3

P: n/a
Ken wrote:
What am I doing wrong?

I set the variable co_name on the first page with an <input.... > and
session_start() at the top of both pages.

Clicking on a link that takes me to the second page:

Script on the second page.

echo $_SESSION['co_name']; Does not display
value of co_name
echo "Variable name co_name = ".$co_name; Displays value of co_name

One book suggested using echo {$_SESSION['co_name']}; Does not run.

Server is Apache2 Triad

Any suggestions. I would like to use $_SESSION incase I move to another
server without ??register_globals?? ON

Thanks for the help.


Now thinking of it a bit further - please do disregard my other post.
What you want is not sessions, but a way to read form input on another page.

If the form is of method=POST, on the page that is called then you can read
each variable by $_POST["fieldname"], if it's a method=GET of course using
$_GET["fieldname"] or alternatively, $_REQUEST["fieldname"].

Sessions, is a totally different subject.
And you were referring to register_globals, so this is what you wanted and
this doesn't need a session_start() at each page in order to work.

/Andreas
--
Peace and long life ...
Registeret Linux user #292411
Jul 17 '05 #4

P: n/a
Ken
I want to carry variables from the input page through to 2 or 3 other pages;
then save the variables in a table or array for future downloading.

There can be several user transferring data at the same time.

What is the best way to do that?

I thought sessions would keep the data from being intermingled between
users.

What is the operational difference between

$_SESSION['variable]

$variable

$_POST['variable']

Thanks for the help.

Ken

"Ken" <kk******@wi.rr.com> wrote in message
news:IF*******************@twister.rdc-kc.rr.com...
What am I doing wrong?

I set the variable co_name on the first page with an <input.... > and
session_start() at the top of both pages.

Clicking on a link that takes me to the second page:

Script on the second page.

echo $_SESSION['co_name']; Does not display
value of co_name
echo "Variable name co_name = ".$co_name; Displays value of co_name

One book suggested using echo {$_SESSION['co_name']}; Does not run.

Server is Apache2 Triad

Any suggestions. I would like to use $_SESSION incase I move to another
server without ??register_globals?? ON

Thanks for the help.

Jul 17 '05 #5

P: n/a
Ken wrote:
What is the operational difference between

$_SESSION['variable]

$variable

$_POST['variable']


| creation | lifetime | scope
------------+------------------+----------------+---------
$variable | first use | end of script | local
$_POST[] | init (by client) | end of script | global
$_SESSION[] | init (by server) | end of session | global

I think this pretty much sums it up :)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.