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

Passing an array by get method

P: 16
Hi,
I need to pass an array by link:

<a href=somfile.php?array=$my_array>

I've tried to make it string (with join) but it doesn't work for big arrays (max size for string parameters is ~255 characters).

Is there a way to pass a big array and get it in $GET variable?

Thanks
Feb 9 '07 #1
Share this Question
Share on Google+
7 Replies


P: 16
I could pass it by using the serialize() function.
Feb 9 '07 #2

Motoma
Expert 2.5K+
P: 3,235
You could put the array in a hidden variable and use javascript in an onlclick for the link to submit the form. You could store your array in a session variable. I don't think you can send larger bits of data over get, however.
Feb 9 '07 #3

ronverdonk
Expert 2.5K+
P: 4,258
The total maximum size of a GET url string is approx. 2800 bytes (under Windows).

That may look a lot, but it is not if you pass a page of text. So, when you suspect it to be larger, it is adviseable to POST the array. You can use the PHP cURL functions to do that for you.

Ronald :cool:
Feb 10 '07 #4

P: 16
Thank you for your replies!

When I was writhing my question I knew nothing about this target. Now with your help I know too much and can't make the right decision:)

Can you help me to choose the most suitable and correct way in this case:

I have an array with integer values, its length could be about 2000 elements. Actually I need it in the next page as a string (joined with comma).

My first question is pass it as string or an array? and second how?

I've tried $_SESSION and $_GET both work OK (some problems with $_GET in IE: the string was cut. but in Mozilla works OK ). Also I've checked my PHP installed with cURL, so I can use it. Or maybe Javascript???

Thanks in Advance
Feb 12 '07 #5

ronverdonk
Expert 2.5K+
P: 4,258
What is wrong with using the $_SESSION array for this. You can assign your array to $_SESSION and use this in another page. As long as you do not forget to use start_session at the top of the scripts!

The following sample shows this. It sets up an aray of 1000 entries, each entry also holding an array. It is then assigned to the $_SESSION array and the content is printed out. Try it out.

[php]<?php
session_start();

$myArray = array(); // define the test array
$max = 1000; // no of array entries to build

// construct the test array
for ($i=0; $i<$max; $i++) {
$myArray[$i] = array("test$i" => "value$i");
}

// show the test array
echo '<b>Content Dump Of The Array I Built:</b><br>';
echo '<pre>'; print_r($myArray);

// assign the test array to the $_SESSION array
$_SESSION['anarray'] = $myArray;

// show the test array in $_SESSION
echo '<b>Content Dump Of $_SESSION Array:</b><br>';
print_r($_SESSION);

// show each entry of the test array in the $_SESSION array
echo '<b>Content Of My Array In $_SESSION Array:</b><br>';
for ($i=0; $i<max; $i++) {
echo "key=test$i - value={$_SESSION['anarray'][$i]["test$i"]}<br>";
}
?>[/php]
Ronald :cool:
Feb 12 '07 #6

P: 16
Thank you very much!!!!
Feb 13 '07 #7

ronverdonk
Expert 2.5K+
P: 4,258
You are most welcome.

Ronald :cool:
Feb 13 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.