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

Hyperlink and passing of variables.

P: n/a
Hello,

I know three ways to pass variables form one page to another. The first
one is to declare and set session variable. In this case if one goes to
another page (by clicking on hyperlink or pressing a button) value of a
session variable will be automatically seen on the new page. The second
way is to set hidden variables in the form and go to new page by
execution of this form (press a button or enter), and the last way,
which I know, is in the declaration of hyperlink after name of a new
page put after "?" names and values of variables. Sometimes I need
to use the third way. However I do not like that after new page is
loaded in the address line of browser one can see all variables (names
and values). Can one avoid this problem?

Jul 24 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

<op*********@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hello,

I know three ways to pass variables form one page to another. The first
one is to declare and set session variable.
Assuming that you have session_start() at the beginning of both pages?
In this case if one goes to
another page (by clicking on hyperlink or pressing a button) value of a
session variable will be automatically seen on the new page. The second
way is to set hidden variables in the form and go to new page by
execution of this form (press a button or enter),
???? Hitting the enter button will only have variables on that page unless
you do what you call the first or third methods. What do you mean here?
and the last way,
which I know, is in the declaration of hyperlink after name of a new
page put after "?" names and values of variables. Sometimes I need
to use the third way. However I do not like that after new page is
loaded in the address line of browser one can see all variables (names
and values). Can one avoid this problem?


Yes. Create a variable which is an array. Put in the values you want for
each variable as:

theArray['first_var'] = first value;

Then create a single session variable which is $_SESSION['theValues'] =
$theArray and pass that single array via the ?thevalues = $theArray.

At the other end you say:

theArrayReceived = $_GET['thevalues'];

and you have an array that you can get the values via the indexing.

I haven't tried it, but it might also work without the creation of the
session variable step. IOW, say

?thevalues=theArray; and on the other end say theArrayReceived=
$_GET['thevalues'];

When I get home from vacation, I will try it. If you try this and it works
without the session variable step, please let me know.

Shelly
Jul 24 '05 #2

P: n/a
I am not sure, that I understood what I need to do.
Create a variable which is an array. Put in the values you want for
each variable as:
theArray['first_var'] = first value; OK. Let say in the file "first.php" I write:
theArray[first] = "aaaa";
theArray[second] = "bbb";
Is it what I need to do?
Then create a single session variable which is $_SESSION['theValues'] =
$theArray What does it mean "to create session variable"? I think I need to
open session by "session_start();" and then I register a session
variable by "session_register( "_SESSION" );", where _SESSION is
the variable name. Do I correctly understand? By the way, what for I
need to put "magical" symbol "_" in the variable name?
and pass that single array via the ?thevalues = $theArray. Do you mean that I need to create hyperlink in the following way?
<a href="second.php?thevalues = $theArray"> Press here </a>
At the other end you say: Under "other end" do you understand the second file (file where I want
to pass variable values)?
theArrayReceived = $_GET['thevalues'];

This line I do not understand. I sees symbol "$" and suppose that
"_GET" is variable name. But I think that my supposition is wrong
since variable with such name never has been declared... How this line
should be understood?

Jul 24 '05 #3

P: n/a

<op*********@yahoo.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
I am not sure, that I understood what I need to do.
Create a variable which is an array. Put in the values you want for
each variable as:
theArray['first_var'] = first value;

OK. Let say in the file "first.php" I write:
theArray[first] = "aaaa";
theArray[second] = "bbb";
Is it what I need to do?
Then create a single session variable which is $_SESSION['theValues'] =
$theArray

What does it mean "to create session variable"? I think I need to
open session by "session_start();" and then I register a session
variable by "session_register( "_SESSION" );", where _SESSION is
the variable name. Do I correctly understand? By the way, what for I
need to put "magical" symbol "_" in the variable name?


No. Here it is (assuming your are at PHP 4 or greater).

To create the session variable you do:

$_SESSION['the_variable_name_you_choose'] =
the_value_or_variable_to_be_assigned_to_it;

The variable name is anything you want. All you need be consistent about is
using the same index in both the setting and the using pages.

Example 1:
in the setting page
$_SESSION['my_address'] = 'this_is_my_address';
in the using page:
$myAge = $_SESSION['my_address'];

The variable $myAge will contain the value 'this_is_my_address'.

Example 2:
in the setting page:
$theArray = array();
$theArray['my_address'] = 'this_is_my_address';
$theArray['my_name'] = 'this_is_my_name';
$_SESSION['my_values'] = $theArray;

in the using page:
$anArray = $_SESSION['my_values'];
and you have
$anArray['my_address'] and $anArray['my_name'] having the correct values.

What I was asking was that in example 2 if you did
<a href=URL_of_using_page?thevalues=<?php echo $theArray ?> >
and in the using page use
$anArray = $_GET['thevalues'];
would that work? I think so, but am not sure. I am sure that example 2
works.

Shelly
Jul 24 '05 #4

P: n/a
op*********@yahoo.com wrote:
Hello,

I know three ways to pass variables form one page to another. The first
one is to declare and set session variable. In this case if one goes to
another page (by clicking on hyperlink or pressing a button) value of a
session variable will be automatically seen on the new page. The second
way is to set hidden variables in the form and go to new page by
execution of this form (press a button or enter), and the last way,
which I know, is in the declaration of hyperlink after name of a new
page put after "?" names and values of variables. Sometimes I need
to use the third way. However I do not like that after new page is
loaded in the address line of browser one can see all variables (names
and values). Can one avoid this problem?


You can't. When using the $_GET method to pass variables from one page to
another, they will end up in the location link (and can be changed by the users).

You're best bet is to use sessions.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 24 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.