send an array through post and get method

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

send an array through post and get method

Post by yaron »

Hello,
Is it possible to send an array through post or get?
page1:

$arr=array('hello','goodbye');
echo "<a href=page2.php?a=$arr>tp page 2</a>";

page2:
if(isset($a))
print_r($a);

and the same for post...

Thanks..
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Nope, I tested it, I get Array echoed out. If you want, you might want to do like:

Page 1:

Code: Select all

<?
$arr=array('hello','goodbye');
$arr=implode(",",$arr);
echo "<a href=pg2.php?a=$arr>tp page 2</a>"; 
?>
Page 2:

Code: Select all

<?
if(isset($a)) {
$a = explode(",", $a);
echo $a[0];
}
?>
-Nay
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

Post by yaron »

will this work if i make a more complex array (with elements that are arrays too)?
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

I don't think so, It'll get all jumbled up.

-Nay
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

Post by yaron »

can't I use [] like we do on checkbox selection for example?
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

I'm not sure. I'm not very familiar with arrays. I use MySQL for all my data needs.

-Nay
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

i c

Post by yaron »

ok, I'll try it
thx anyway
p.s
nice pic :-)
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

haha, thanks. Which one btw? :-D. The pic that appears are random.

-Nay
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

Post by yaron »

hmmm... yes you are right...
well, they are all nice...haha
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

errrr.....why not use sessions?

Then your arrays, no matter how complex will be available to your scripts.

Unless you REALLY need to use post or get, but without stating your reason for wanting to achieve this, i can't say much more.

Mark
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

Post by yaron »

I thought about that but i have a problem.
I create a table full of links each needs to send different values i.e. my array.
the easiest is using <a href> with get method. I can't create so many sessions it will slow my server.
I thought about using the post method to send my array as a string and explode it later. is it possible to create so many forms? an I submit them without specify a form name?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

why not just send one unique value on the <a href> then on the next page, generate your array depending on that value.

Mark
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I can't create so many sessions it will slow my server.
are you sure loading the session-data when needed is slower than shifting the data forth and back the inet connection over and over again?

implode() can handle multidimensional arrays.
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

Post by yaron »

I can't do that...
I have to much data to send.
I think the post thing will work I jave just 1 problem with that..
because I have many forms and I gave them unique names e.g. f1,f2,f3....
I try to send to the java script function in order to submit a form but when I can't seem to be able to eval my form name in the js func
any ideas?
Post Reply