Hyperlink and passing of variables.

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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?

Re: Hyperlink and passing of variables.

Quoted text here. Click to load it

Assuming that you have session_start() at the beginning of both pages?

Quoted text here. Click to load it

????  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?

Quoted text here. Click to load it

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=  

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.


Re: Hyperlink and passing of variables.

I am not sure, that I understood what I need to do.

Quoted text here. Click to load it
OK. Let say in the file "first.php" I write:
theArray[first] = "aaaa";
theArray[second] = "bbb";
Is it what I need to do?

Quoted text here. Click to load it
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?

Quoted text here. Click to load it
Do you mean that I need to create hyperlink in the following way?
<a href="second.php?thevalues = $theArray"> Press here </a>

Quoted text here. Click to load it
Under "other end" do you understand the second file (file where I want
to pass variable values)?

Quoted text here. Click to load it
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?

Re: Hyperlink and passing of variables.

Quoted text here. Click to load it

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 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  


Re: Hyperlink and passing of variables.

opt_inf_env@yahoo.com wrote:
Quoted text here. Click to load it

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.

Site Timeline