Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing arrays between urls 2

Status
Not open for further replies.

NVSbe

Programmer
Joined
Sep 9, 2002
Messages
153
Location
BE
In call.php, I have three arrays, data1, data2 and data3. I'd like to pass them to script.php in the form of:
script.php?data1=$data1&data2=$data2&data3=$data3

but if I do this, and use a $_GET to fetch the results, it appears all that has been passed is the word "Array". Is that normal?

--------------------------------------
It's not the monsters under your bed, it is the men next door.
That make you fear, make you cry. Make you cry for the Child.
All the wars are fought amongst those lonely men. Unharmed, unscarred.
 
It is the expected behaviour, yes. You would probably want to [tt]serialize[/tt]() the arrays and [tt]unserialize[/tt]() them in [tt]script.php[/tt].

//Daniel
 
I strongly suggest that you use the session capabilities of PHP.
All you need is start a session in both scripts using the start_session();
Code:
# call.php
start_session();
$myArray[] = "data1";
$myArray[] = "data2";
$_SESSION['myArray'] = $myArray;
# etc....

# script.php
start_session();
$myArray = $_SESSION['myArray'];
This way you need not worry about the encoding etc. The data is stored on the server between accesses and there is no restriciton to size. The only thing passed to the browser is a cookie with the unique session ID.

If you really want to pass it in the URL, you just write a URL query string out with a foreach loop. If you just use the print command it will only say 'Array' since arrays can't be output using the print command.
 
Thank you so very much... I'm rather new to php, you see, and the amount of information out there is just overwhelming ;)

--------------------------------------
It's not the monsters under your bed, it is the men next door.
That make you fear, make you cry. Make you cry for the Child.
All the wars are fought amongst those lonely men. Unharmed, unscarred.
 
About sessions. I have heard about them, but since this is my second day in php, I have yet to use them. It didn't seem convenient to me in this example, because the script.php url is a script that uses the data in the arrays to make a bar graph with the JPGraph package.. like this:

<?php

$data1 = array(1,2,3,4);
$data2 = array(1,2,3,4);
$data3 = array(1,2,3,4);

$sdata1 = serialize($data1);
$sdata2 = serialize($data2);
$sdata3 = serialize($data3);

?>

<img src=<?php echo &quot;\&quot;script.php?data1=&quot;. $sdata1. &quot;&data2=&quot;. $sdata2. &quot;&data3=&quot;. $sdata3. &quot;\&quot;&quot; ?>>

Of course, in the future, I'll be looking into sessions.

--------------------------------------
It's not the monsters under your bed, it is the men next door.
That make you fear, make you cry. Make you cry for the Child.
All the wars are fought amongst those lonely men. Unharmed, unscarred.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top